
The touch command can be used to create and edit files. The touch command followed by a file name will either create a new, empty file, or update the last accessed time of the file if it already exists. In this example, there are no files in the /home/john.doe directory.
[john.doe@server1 ~]# ls -l /home/john.doe
In this scenario, the touch command followed by a file name will create a new, empty file named example.file.
[john.doe@server1 ~]# touch example.file
Because the file is empty, the newly created file is 0 bytes.
[john.doe@server1 ~]# ls -l /home/john.doe
-rw-r--r-- john.doe john.doe 0 Jan 01 21:17:16 example.file
Now that example.file exists, the touch command followed by example.file will update the last accessed time of example.file. In this example, the last modified time is updated from 21:17:16 to 21:23:14. This will not modify the contents of the file, and the last modified file will not be changed.
[john.doe@server1 ~]# touch example.file
[john.doe@server1 ~]# ls -l /home/john.doe --time=atime
-rw-r--r-- john.doe john.doe 0 Jan 01 21:23:14 example.file
Did you find this article helpful?
If so, consider buying me a coffee over at