Create a New, Empty File


touch

But that's not the main reason many people use touch. The command has an interesting effect if you try to use the touch command on a file that doesn't exist: It creates an empty file using the name you specified.

$ ls -l ~/ drwxr-xr-x   848 2005-10-19 11:36 src drwxr-xr-x   632 2005-10-18 12:25 videos $ touch test.txt $ ls -l ~/ drwxr-xr-x   848 2005-10-19 11:36 src -rw-r--r--     0 2005-10-19 23:41 test.txt drwxr-xr-x   632 2005-10-18 12:25 videos 


Why would you use touch in this way? Let's say you want to create a file now, and then fill it with content later. Or you need to create several files to perform tests on them as you're playing with a new command you've discovered. Both of those are great reasons, and you'll find more as you start learning more about your shell.



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