$linuxjunkies
>

touch(1)

Create empty files or update the access and modification times of existing files.

UbuntuDebianFedoraArch

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

FlagWhat it does
-achange only the access time
-mchange only the modification time
-cdo not create the file if it does not exist
-d DATEset the time to DATE (e.g., '2024-01-15 10:30:00')
-t STAMPset the time to STAMP in format [[CC]YY]MMDDhhmm[.ss]
-r FILEset the time to match FILE's timestamp
-haffect symbolic links themselves, not their targets

Examples

create an empty file named myfile.txt, or update its timestamp if it exists

touch myfile.txt

create or update three files at once

touch file1.txt file2.txt file3.txt

update oldfile.txt's timestamp only if it already exists; do not create it

touch -c oldfile.txt

set target.txt's timestamp to match reference.txt's timestamp

touch -r reference.txt target.txt

set archive.txt's timestamp to January 15, 2024 at 2:30 PM

touch -d '2024-01-15 14:30:00' archive.txt

set logfile.txt's timestamp using the format YYYYMMDDhhmm (2024-01-15 14:30)

touch -t 202401151430 logfile.txt

update only the access time of file.txt, leaving modification time unchanged

touch -a file.txt

update only the modification time of file.txt, leaving access time unchanged

touch -m file.txt

Related commands