Create new file using the TOUCH command in Linux

Home > Search > Linux commands
  by

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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments