LinuxCommandLibrary

touch

Update file access/modification timestamps

TLDR

Create specific files

$ touch [path/to/file1 path/to/file2 ...]
copy

Set the file [a]ccess or [m]odification times to the current one and don't create file if it doesn't exist
$ touch [[-c|--no-create]] -[a|m] [path/to/file1 path/to/file2 ...]
copy

Set the file [t]ime to a specific value and don't create file if it doesn't exist
$ touch [[-c|--no-create]] -t [YYYYMMDDHHMM.SS] [path/to/file1 path/to/file2 ...]
copy

Set the files' timestamp to the reference file's timestamp, and do not create the file if it does not exist
$ touch [[-c|--no-create]] [[-r|--reference]] [path/to/reference_file] [path/to/file1 path/to/file2 ...]
copy

SYNOPSIS

touch [OPTION]... FILE...

PARAMETERS

-a
    Change only the access time.

-c, --no-create
    Do not create any files that do not exist. Suppress error messages about non-existent files.

-d, --date=STRING
    Parse STRING and use it as the modification and access times instead of the current time.

-f
    Ignored; included for compatibility with older systems. Does nothing.

-m
    Change only the modification time.

-r, --reference=FILE
    Use the access and modification times of FILE instead of the current time.

-t STAMP
    Use [[CC]YY]MMDDhhmm[.ss] as the modification and access times. The digits specify the year, month, day, hour, minute, and optionally, the second.

--time=WORD
    Change the specified time: access, atime, or use are equivalent to -a; modify or mtime are equivalent to -m

--help
    Display help message and exit.

--version
    Output version information and exit.

DESCRIPTION

The touch command is a standard Unix/Linux utility used to update the access and modification times of a file. If the file does not exist, touch creates an empty file with the specified name. This is its most common usage. It is particularly useful for managing timestamps in build systems (like Makefiles) or forcing updates in software where file modification times are important. The command does not modify the file's content.
The primary function is to update timestamps, and the command supports options to set specific timestamps, rather than using the current system time. The command is a basic, yet essential part of any Linux distribution.

TIMESTAMP FORMAT

The '-t' option accepts a timestamp in the format [[CC]YY]MMDDhhmm[.ss]. CC is the century, YY is the year, MM is the month, DD is the day, hh is the hour, mm is the minute, and .ss is the optional seconds. If CC is omitted, years 69-99 are assumed to be 1969-1999 and years 00-68 are assumed to be 2000-2068.

HISTORY

The touch command has been a part of Unix systems for a long time. Its primary function has always been to create empty files or to update file access and modification times. The core functionality remains consistent across different Unix-like operating systems, although minor variations in available options might exist.

SEE ALSO

stat(1), find(1)

Copied to clipboard