utility

touch — external utility

Creates missing files unless -c is supplied and updates access/modification times on existing files without truncating them. -t accepts a timestamp; TZ affects its interpretation. It cannot arbitrarily set status-change time. Fixture uses UTC and a known file. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Expected output (one item per line): 2024-01-02 03:04:05; data.

Formal Syntax & Structure

bash syntaxbash
touch [-acm] [-t STAMP] [--] FILE...

Parameters & Attributes

NameTypeDescription
FILEpathTarget file path.

Return Value

exit status

Zero on successful operation; nonzero on errors.

Working Example

Example Snippetbash
printf 'data\n' > sample.txtTZ=UTC touch -t 202401020304.05 -- sample.txtTZ=UTC date -r sample.txt '+%Y-%m-%d %H:%M:%S'cat sample.txt
Bash Reference