Chapter 6 . Managing Files 241 Table 6-6 Options Used with touch Option Use -c Do not create a file if none exists. -d Used to specify the stamp on the file instead of using the current time. r Uses the time of the instead of the current time. -t Uses an argument to specify the time instead of using the current time. -a Only changes the access time on the file. As you can see, the touch command allows you to use the current time or to specify a time for the time stamp. The command is often used to create an empty file with the specified name. This can be useful when running other scripts that expect a file to exist. Log files are one example of a type of file that is automatically written to and sometimes must exist to avoid errors in logging. If the file is archived elsewhere you might want to delete the original file. You can then use touchto create an empty file used to store the log information. This command is often run in scripts as cron jobs at specified times. The touchcommand allows this process to run automatically with no user intervention and no error messages generated due to a missing file. The following example shows a script in which the touch command is used to create an empty file. cp mylogs stuff/mylogs.`date +%m.%d.%y` rm -f mylogs touch mylogs This will copy the contents of the mylogs file to a file located in the stuff directory with a filename of mylogs.month.day.year, (for example, mylogs. 12.11.00). The original mylogs file is deleted, and then the touchcommand is used to create an empty file named mylogs. This is one common use of the touch command. Copying files When working with files on any system, you often need to copy files. Linux includes two commands for file copying. The cp command is used to copy files and directories. This is the standard command used when copying files from one location on the system to another. When copying files from one file format to another the dd command is used. Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.
This entry was posted
on Tuesday, September 18th, 2007 at 7:04 pm and is filed under apache .
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response , or trackback from your own site.