The touch Command

Creating a new empty file in Unix is easy when you use the touch command. The touch command is used to update the last modified time of a file, setting it to the current time. This is usually not commonly used, but knowing about it can serve you well. The touch command is normally used with one particular area: backup and disaster recovery. As a Unix system administrator, you may be asked to do backup and restore jobs. There are a few different types (and methods) of backup and restore you can choose from, one of which is called an ”incremental backup. Although this may not be something you work with in Unix, it is something you are most likely affected by. Most systems are backed up and protected by companies that need to save and keep their valuable data.

The touch command can be used with the incremental backup by helping to verify that a backup was in fact completed. Even if you never altered the data or modified it for any reason, you can still use the touchcommand to change the modification date and make it appear as if it had been modified, thus making it appear to have been modified at the time you touched it. This can be useful when you work with backups in particular, and you may also find other uses for it in your work with Unix.

Where Did That New File Come From? When you ”touch” a file by accident, you may wind up with a new file you may not have wanted. If you use the touch command and do not specify the actual filename (a file that really exists on your system), Unix will create a new file for you. For example, if you said you wanted to touch a file on your system named unixmaster, and it was really called unixmasters, then a unixmaster file will be created by Unix within the current directory you are working (or saving). You can do this by typing pwd.


Now that you understand the touch command, let's take a look at how you can use it. In this example we will look at both how to change the modification date of a file and how to make a new file altogether.

1.
Determine the filename of the file or files you want to update or create.

2.
Issue the touch command as touch <filename>.

For example, type

						> touch backupfile
					

If the backup file previously existed, its last-modified date would now be set to the current time. If the backup file did not previously exist, it would now exist as an empty file with a last-modification date of the current time. It's that easy.

There are additional uses for the touch command. When you become comfortable enough with Unix to start automating your work using shell scripting (discussed in Lesson 14, “Shell Scripting Fundamentals”), you will find the touch command useful for creating “flag files” that allow your scripts to talk to each other. Keep the touch command in mind during Lesson 14.

Use Your Time Correctly When working with Unix, (or any other operating system), you should have the correct time set on your system. This is usually done by a system administrator, as it's normally not done locally on the system. Instead, a time master is usually found somewhere on the network, from which your Unix system may pull the time. Of course, if your Unix system is not networked, then you will most likely be getting your correct time from the local system. Be aware of what time your Unix system says and where you are getting your time from.

Having your Unix system set with the proper time will help not only with file management, but also with logging and security.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.49.190