touch(1)
Create empty files or update the access and modification times of existing files.
Synopsis
touch [OPTION]... FILE...Description
touch creates a new empty file if it does not exist, or updates the access and modification timestamps of an existing file to the current time. It is commonly used in shell scripts to create placeholder files and to update timestamps without modifying file contents.
If the file already exists, touch does not alter its contents—only its timestamps are updated. If the file does not exist, it is created with default permissions (modified by the current umask).
Common options
| Flag | What it does |
|---|---|
-a | change only the access time |
-m | change only the modification time |
-c | do not create the file if it does not exist |
-d DATE | set the time to DATE (e.g., '2024-01-15 10:30:00') |
-t STAMP | set the time to STAMP in format [[CC]YY]MMDDhhmm[.ss] |
-r FILE | set the time to match FILE's timestamp |
-h | affect symbolic links themselves, not their targets |
Examples
create an empty file named myfile.txt, or update its timestamp if it exists
touch myfile.txtcreate or update three files at once
touch file1.txt file2.txt file3.txtupdate oldfile.txt's timestamp only if it already exists; do not create it
touch -c oldfile.txtset target.txt's timestamp to match reference.txt's timestamp
touch -r reference.txt target.txtset archive.txt's timestamp to January 15, 2024 at 2:30 PM
touch -d '2024-01-15 14:30:00' archive.txtset logfile.txt's timestamp using the format YYYYMMDDhhmm (2024-01-15 14:30)
touch -t 202401151430 logfile.txtupdate only the access time of file.txt, leaving modification time unchanged
touch -a file.txtupdate only the modification time of file.txt, leaving access time unchanged
touch -m file.txt