touch — Create Files and Set Timestamps

Create empty files or update file access and modification timestamps. Essential for creating placeholder files, triggering build systems, and managing file metadata.

touch does two things: it creates empty files and it updates the timestamps of existing files – the access time (atime) and the modification time (mtime). If the file does not exist yet, it is created empty; if it already exists, its contents are left untouched and only the timestamps move to "now". That makes touch the go-to tool for placeholders like .gitkeep, for health-check markers in containers, and for nudging build systems such as make into rebuilding. This guide covers creating files, setting specific timestamps, and common real-world patterns.

Create Files

touch <file> — Create an empty file (or update timestamp if it exists).

touch newfile.txt

touch <file1> <file2> <file3> — Create multiple files at once.

touch index.html style.css script.js

touch -c <file> — Update timestamp only if file exists (do not create).

touch -c maybe-exists.txt

Set Specific Timestamps

touch -t <YYYYMMDDhhmm> <file> — Set a specific date and time.

touch -t 202601011200 file.txt

touch -t <YYYYMMDDhhmm.ss> <file> — Set date, time and seconds.

touch -t 202601011200.30 file.txt

touch -d '<date string>' <file> — Set timestamp using a human-readable date string.

touch -d '2026-01-15 14:30:00' file.txt

touch -d 'next Monday' <file> — Set timestamp using relative date expressions.

touch -d 'next Monday' reminder.txt

touch -d '-2 days' <file> — Set timestamp to 2 days ago.

touch -d '-2 days' oldfile.txt

Modify Specific Timestamps

touch -a <file> — Update only the access time (atime).

touch -a data.log

touch -m <file> — Update only the modification time (mtime).

touch -m config.yaml

touch -r <reference> <file> — Set timestamp to match another file's timestamp.

touch -r original.txt copy.txt

touch -a -d '<date>' <file> — Set a specific access time.

touch -a -d '2026-06-01' data.csv

Common Patterns

touch .gitkeep — Create a placeholder to keep an empty directory in Git.

mkdir -p logs && touch logs/.gitkeep

touch -r <src> <dest> — Synchronize timestamps between files.

touch -r photo.jpg photo_edited.jpg

find . -name '*.txt' -exec touch {} + — Update timestamps of all matching files.

find . -name '*.cache' -exec touch {} +

touch /tmp/.healthcheck — Create a health-check marker file (common in Docker).

touch /tmp/.healthcheck

touch -d '1970-01-01' <file> — Set timestamp to Unix epoch (force rebuild in build systems).

touch -d '1970-01-01' Makefile

Conclusion

touch is unassuming but surprisingly versatile in daily work: the fastest way to create empty files and the simplest way to manipulate timestamps deliberately. With -t and -d you set date and time absolutely or relatively, with -a/-m you change only the access or modification time, and with -r you copy the time from a reference file. This is especially handy with build systems like make, which base their decisions on mtime – a targeted touch forces or prevents a rebuild. Keep in mind that touch never empties an existing file: it only changes metadata, never the contents.

Further Reading

  • mkdir – create directories
  • stat – show a file's timestamps and metadata
  • ls – list directory contents and timestamps