touch
Commandtouch
The touch
command is commonly used to create an empty file or update the access and modification timestamps of an existing file:
touch [file_name]
If the file doesn’t exist, it will create a new, empty file. If the file already exists, it will update the file’s access and modification times.
touch
touch -a
(Change Access Time)Updates the access time of the file without affecting the modification time:
touch -a file.txt
This will only update the last accessed time of file.txt
.
touch -m
(Change Modification Time)Updates the modification time of the file without affecting the access time:
touch -m file.txt
This will only update the last modification time of file.txt
.
touch -t
(Set Specific Time)Manually sets the access and modification times to a specific time:
touch -t 202309221200 file.txt
This sets the timestamp of file.txt
to "September 22, 2023, 12:00 PM". The format is [[CC]YY]MMDDhhmm[.ss]
.
touch -c
(No Create)Prevents touch
from creating a new file if it doesn’t already exist:
touch -c file.txt
If file.txt
doesn’t exist, touch
will do nothing and won’t create a new file.
touch -r
(Reference Another File)Uses the timestamps of another file to set the access and modification times of a target file:
touch -r reference.txt file.txt
This sets the timestamps of file.txt
to match those of reference.txt
.
touch --help
Displays help information for the touch
command:
touch --help
Option | Description |
---|---|
touch [file_name] |
Create an empty file or update its timestamp. |
touch -a [file] |
Update the access time only. |
touch -m [file] |
Update the modification time only. |
touch -t [timestamp] [file] |
Set a specific timestamp for a file. |
touch -c [file] |
Do not create the file if it does not exist. |
touch -r [ref_file] [file] |
Use another file’s timestamp to set the time of a target file. |
touch --help |
Display help information for the touch command. |
For more detailed information, use the manual page for the touch
command:
man touch