There's a substantial difference between the two. Touch
is a command used to time stamp a file. The >
symbol is a standard output redirector.
Usage of the two explained
Usage of Touch
If the file doesn't exist it will create the file.
Touch is commonly used to create flags. For instance if you want to find all files between two times on your system you could use this sequence of commands:
$ touch -t 201609292200 starttime
$ touch -t 201609292300 endtime
This will create the following files (or change the time-stamp if they exist):
-rw-rw-r-- 1 ljames ljames 0 Sep 29 23:00 endtime
-rw-rw-r-- 1 ljames ljames 0 Sep 29 22:00 starttime
Now you can use find to display or process all files that were modified on that hour (time between those two files time stamps, i.e. between 10 PM and 11 PM of September 29, 2016).
$ find ~/ -newer starttime ! -newer endtime -printf "%M %Tm/%Td %TH:%TM %TM %p\n"
This is a partial output of the above find command:
-rw-rw-r-- 09/29 22:08 08 /home/users/l/j/ljames/.thunderbird/lj7p62iq.default/gcontactsync/google_feed_backups/[email protected]_groups.xml
-rw-rw-r-- 09/29 22:08 08 /home/users/l/j/ljames/.thunderbird/lj7p62iq.default/gcontactsync/google_feed_backups/[email protected]
-rw-rw-r-- 09/29 22:08 08 /home/users/l/j/ljames/.thunderbird/lj7p62iq.default/gcontactsync/address_book_backups/abook.mab.bak
-rw-rw-r-- 09/29 23:00 00 /home/users/l/j/ljames/endtime
drwx------ 09/29 22:44 44 /home/users/l/j/ljames/.config/google-chrome/Default/Extensions/Temp
drwx------ 09/29 22:44 44 /home/users/l/j/ljames/.config/google-chrome/Default/Extensions/fahmaaghhglfmonjliepjlchgpgfmobi
drwx------ 09/29 22:44 44 /home/users/l/j/ljames/.config/google-chrome/Default/Extensions/fahmaaghhglfmonjliepjlchgpgfmobi/1.337.0_0
Usage of Output redirection
The redirecting Symbol will redirect standard output to the specified file. Depending on your clobber/noclobber settings if could fail. Noclobber will only create the file if it doesn't exist.
There are a number of versions of the redirection output which includes:
> - Redirect standard output. Create or overwrite the existing file.
>> - Redirect append. Create or append to existing file.
>& - Redirect both standard output and standard error.
>>& - Redirect/Append both standard output and standard error
We could use our find
command above to redirect the contents of all files created within the specified hour to a file that we could log and study later:
$ find ~/ -newer starttime ! -newer endtime -printf "%M %Tm/%Td %TH:%TM %TM %p\n" > ~/files.log
file.txt
already exists and is not empty, they certainly don't.touch
a file that contains data nothing will happen but if you>
the file it will be erased.