CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / File & Directory Management / touch

touch

Create empty files or update timestamps

Beginneressentialfilesystemtimestamps

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.

Syntaxtouch [OPTION]... FILE...

Watch it run

You need an empty placeholder file, and later want to mark it as just updated.

devops@devops-lab: ~/logs — zsh — 96×28
➜ ~/logs
Step 1 of 4
touch app.log && ls -l app.log

The file didn't exist, so touch created it: 0 bytes, mode 664 from your umask.

Anatomy of a command

$
commandtouch

Set timestamps; create the file if it's missing.

How it works

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.

Options you'll actually use

-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's

Common mistakes

touch file.txt to 'save' or 'refresh' its contents

touch never changes content; it only updates timestamps (and creates empty files).

Edit the file, or echo/printf > file to write content
touch 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 exist
Trusting mtime to prove when a file was last modified in a security investigation

Anyone who owns the file can set atime and mtime with touch -d.

Compare with ctime (stat), which only the kernel sets, plus audit logs

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Create ten empty files ~/scratch/test-1.log ... test-10.log with one command.

  2. 2

    Make ~/scratch/test-1.log look 15 days old, then use find to list files older than 7 days in ~/scratch.

  3. 3

    Give ~/data/notes.txt the same timestamps as ~/data/orders.csv and verify with stat.

Related commands

statShow a file's inode: size, permissions, owner and timestampsfindSearch the filesystem by name, size, age, owner and moremkdirCreate directorieslsList directory contents
PreviousrmdirNextfind
Linux / File & Directory Management / touch

touch

Create empty files or update timestamps

Beginneressentialfilesystemtimestamps

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.

Syntaxtouch [OPTION]... FILE...

Watch it run

You need an empty placeholder file, and later want to mark it as just updated.

devops@devops-lab: ~/logs — zsh — 96×28
➜ ~/logs
Step 1 of 4
touch app.log && ls -l app.log

The file didn't exist, so touch created it: 0 bytes, mode 664 from your umask.

Anatomy of a command

$
commandtouch

Set timestamps; create the file if it's missing.

How it works

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.

Options you'll actually use

-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's

Common mistakes

touch file.txt to 'save' or 'refresh' its contents

touch never changes content; it only updates timestamps (and creates empty files).

Edit the file, or echo/printf > file to write content
touch 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 exist
Trusting mtime to prove when a file was last modified in a security investigation

Anyone who owns the file can set atime and mtime with touch -d.

Compare with ctime (stat), which only the kernel sets, plus audit logs

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Create ten empty files ~/scratch/test-1.log ... test-10.log with one command.

  2. 2

    Make ~/scratch/test-1.log look 15 days old, then use find to list files older than 7 days in ~/scratch.

  3. 3

    Give ~/data/notes.txt the same timestamps as ~/data/orders.csv and verify with stat.

Related commands

statShow a file's inode: size, permissions, owner and timestampsfindSearch the filesystem by name, size, age, owner and moremkdirCreate directorieslsList directory contents
PreviousrmdirNextfind