Linux touch command – change file timestamps
Linux touch command is used to modify the time attributes of a file or directory, including access time and modification time. If the file does not exist, the system will create a new file.
Syntax
touch [OPTION]... FILE...
Options
- -a
change only the access time - -c, –no-create
do not create any files - -d, –date=STRING
parse STRING and use it instead of current time - -f
ignored, it is reserved for compatibility with other unix systems - -h, –no-dereference
affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink) - -m
change only the modification time - -r, –reference=FILE
use this file’s times instead of current time - -t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time - –time=WORD
change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m
Examples & Use Cases
Update file access and modification times
In the following example, we will update the access and modification time of the test.log file to the current time. Of course, the test.log file is an existing file, otherwise a new file named test.log will be created.
➜ touch test.log
Create multiple empty files at the same time
In the following example, we will use the touch command to create multiple empty files at the same time. Separate multiple file names with spaces.
➜ ~ touch a.log b.log c.log