touchCreate empty files or update timestamps
touch updates a file's access and modification times to now, and creates the file empty if it doesn't exist. DevOps uses: placeholder and marker files, health-check files, and faking a file's age to test cleanup jobs that use find -mtime.
touch [OPTION]... FILE...You need an empty placeholder file, and later want to mark it as just updated.
touchSet timestamps; create the file if it's missing.
Every inode carries timestamps: atime (last read), mtime (last content change), ctime (last inode change: content, permissions, owner, rename) and on modern filesystems a birth time. touch opens the file with O_CREAT if it's missing, creating a new empty inode, then calls utimensat() to set atime and mtime, to now or to the time given with -d, -t or -r. Only atime and mtime can be set by a user; ctime is always set by the kernel to the real current time whenever the inode changes, including by touch itself, which is why ctime can't be faked without changing the system clock. Setting times to now requires write access to the file (or owning it); setting an arbitrary time requires ownership. Tools like make, rsync, find -mtime/-newer and log cleanup scripts all decide what to do from these timestamps.
-cDon't create the file if it doesn't exist-aChange only the access time-mChange only the modification time-d STRINGUse a date string: '2026-10-01 03:00', 'yesterday', '3 days ago'-t STAMPUse [[CC]YY]MMDDhhmm[.ss], e.g. 202610010300-r FILECopy the timestamps of another file-hChange a symlink's own times, not its target'stouch file.txt to 'save' or 'refresh' its contentstouch never changes content; it only updates timestamps (and creates empty files).
Edit the file, or echo/printf > file to write contenttouch config.yml with a typo in a deploy step (config.yaml)touch silently creates the misspelled empty file, so the step 'succeeds' and the real file is untouched.
touch -c config.yaml (or test -f first) when the file must already existTrusting mtime to prove when a file was last modified in a security investigationAnyone who owns the file can set atime and mtime with touch -d.
Compare with ctime (stat), which only the kernel sets, plus audit logsTry these on a Linux machine of your own. Each task has a hint and a solution.
Create ten empty files ~/scratch/test-1.log ... test-10.log with one command.
Make ~/scratch/test-1.log look 15 days old, then use find to list files older than 7 days in ~/scratch.
Give ~/data/notes.txt the same timestamps as ~/data/orders.csv and verify with stat.
touchCreate empty files or update timestamps
touch updates a file's access and modification times to now, and creates the file empty if it doesn't exist. DevOps uses: placeholder and marker files, health-check files, and faking a file's age to test cleanup jobs that use find -mtime.
touch [OPTION]... FILE...You need an empty placeholder file, and later want to mark it as just updated.
touchSet timestamps; create the file if it's missing.
Every inode carries timestamps: atime (last read), mtime (last content change), ctime (last inode change: content, permissions, owner, rename) and on modern filesystems a birth time. touch opens the file with O_CREAT if it's missing, creating a new empty inode, then calls utimensat() to set atime and mtime, to now or to the time given with -d, -t or -r. Only atime and mtime can be set by a user; ctime is always set by the kernel to the real current time whenever the inode changes, including by touch itself, which is why ctime can't be faked without changing the system clock. Setting times to now requires write access to the file (or owning it); setting an arbitrary time requires ownership. Tools like make, rsync, find -mtime/-newer and log cleanup scripts all decide what to do from these timestamps.
-cDon't create the file if it doesn't exist-aChange only the access time-mChange only the modification time-d STRINGUse a date string: '2026-10-01 03:00', 'yesterday', '3 days ago'-t STAMPUse [[CC]YY]MMDDhhmm[.ss], e.g. 202610010300-r FILECopy the timestamps of another file-hChange a symlink's own times, not its target'stouch file.txt to 'save' or 'refresh' its contentstouch never changes content; it only updates timestamps (and creates empty files).
Edit the file, or echo/printf > file to write contenttouch config.yml with a typo in a deploy step (config.yaml)touch silently creates the misspelled empty file, so the step 'succeeds' and the real file is untouched.
touch -c config.yaml (or test -f first) when the file must already existTrusting mtime to prove when a file was last modified in a security investigationAnyone who owns the file can set atime and mtime with touch -d.
Compare with ctime (stat), which only the kernel sets, plus audit logsTry these on a Linux machine of your own. Each task has a hint and a solution.
Create ten empty files ~/scratch/test-1.log ... test-10.log with one command.
Make ~/scratch/test-1.log look 15 days old, then use find to list files older than 7 days in ~/scratch.
Give ~/data/notes.txt the same timestamps as ~/data/orders.csv and verify with stat.