touch

What is touch?

touch is used to create a file without any content. The file created using touch command is empty. This command can be used when the user doesnโ€™t have data to store at the time of file creation.

How to use touch

# syntax
touch <FILE>

##### create a empty textfile
touch test.txt

##### create multiple empty textfiles
touch test1.txt test2.txt test3.txt

##### change access time (this is used to change access time only)
touch -a filename.txt

##### check whether a file is created or not. If not, then don't create it. This commands avoids creating files if it already exists
touch -c fileName.txt

##### update access and modification time
touch -c-d '16 sep' fileName.txt

##### change only the modification time
touch -m fileName.txt

##### use the timestamp of another file on a file of your choosing (first_file_name.txt will have the time stamp of second_file_name.txt)
touch -r second_file_name.txt first_file_name.txt

##### create a file using a specified time
touch -t YYMMDDHHMM fileName.txt

Reference

Last updated