Change a File to the Current Time


touch

The touch command isn't one you'll find yourself using constantly, but you'll need it as you proceed through this book, so it's a good one to cover now. Interestingly, the main reason for the existence of touchto update the access and modification times of a fileisn't the main reason you'll be using the command. Instead, you're going to rely on its secondary purpose that undoubtedly gets more use than the primary purpose!

Note

You can only use the touch command on a file and change the times if you have write permission for that file. Otherwise, touch fails.


To simultaneously update both the access and modification times for a file (or folder), just run the basic touch command.

$ ls -l ~/ drwxr-xr-x     848 2005-10-19 11:36 src drwxr-xr-x    1664 2005-10-18 12:07 todo drwxr-xr-x     632 2005-10-18 12:25 videos -rw-r--r--     239 2005-09-10 23:12 wireless.log $ touch wireless.log $ ls -l ~/ drwxr-xr-x     848 2005-10-19 11:36 src drwxr-xr-x    1664 2005-10-18 12:07 todo drwxr-xr-x     632 2005-10-18 12:25 videos -rw-r--r--     239 2005-10-19 14:00 wireless.log 


Thanks to touch, both the modification time and the access time for the wireless.log file have changed, although ls -l only shows the modification time. The file hadn't been used in more than a month, but touch now updates it, making it look like it was just ... touched.

You can be more specific, if you'd like. If you want to change just the access time, use the -a option (or --time=access); to alter the modification time only, use -m (or --time=modify).



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net