4.1 Change the timestamp of file (touch)


Every file has a last update time. It can be checked by using ls -l. The touch command changes this last update time.

Format

touch [option] file-name


You can change the last update time of the specified file. You can also set the time by option. If the specified file does not exist, the touch command creates the file whose contents is empty and the size is 0 byte.



Practice: Confirm the last update time changed


$ ls -l hosts.bak ↵
-rw-rw-r-- 1 okada okada 187 Jun 4 10:06 hosts.bak
$ touch hosts.bak ↵
$ ls -l hosts.bak ↵
-rw-rw-r-- 1 okada okada 187 Jun 5 09:50 hosts.bak
$ touch -t 06030800 hosts.bak ↵
$ ls -l hosts.bak ↵
-rw-rw-r-- 1 okada okada 187 Jun 3 08:00 hosts.bak


-t is an option which specifies update time. Time is specified in [[CC]YY]MMDDhhmm[.SS] format (parts in [] are omissible). Now, we were able to check that the last update time of the file was changed.



Practice: Create a file by touch command


$ ls -l touched-file ↵


(Confirm that the file does not exist.)


$ touch touched-file ↵ $ ls -l touched-file ↵ -rw-rw-r-- 1 okada okada 0 Jun 5 09:55 touched-file


The file is created. The content of the file is empty, and the size is 0 byte.



Previous Next