The touch command in Linux is used to create new, empty files or update the modification time of existing files.
The syntax of touch command is as following,
touch [OPTION]... FILE...
Where OPTION can be
- -a (change only the access time)
- -c (do not create the file if it doesn’t exist)
- -d TIME (use TIME instead of the current time)
- -m (change only the modification time)
- -r FILE (use the timestamps from FILE instead of the current time)
- -t TIME (use the specified TIME in the format YYYYMMDDhhmm.ss)
- or — (end the options and start processing the arguments)
and FILE is the name of the file we want to create or modify.
Some of the examples of using touch command are as below,
$ touch filename.txt
Above command creates an empty file named filename.txt
$ touch -c filename.txt
Above command does not create filename.txt file if it doesn’t exist. This normally can be just used to check the file existence.
$ touch -m file.txt
Above command changes the modification time of filename.txt to the current time, i.e. it just changes the timestamp of file.