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.txttouch <file1> <file2> <file3> — Create multiple files at once.
touch index.html style.css script.jstouch -c <file> — Update timestamp only if file exists (do not create).
touch -c maybe-exists.txtSet Specific Timestamps
touch -t <YYYYMMDDhhmm> <file> — Set a specific date and time.
touch -t 202601011200 file.txttouch -t <YYYYMMDDhhmm.ss> <file> — Set date, time and seconds.
touch -t 202601011200.30 file.txttouch -d '<date string>' <file> — Set timestamp using a human-readable date string.
touch -d '2026-01-15 14:30:00' file.txttouch -d 'next Monday' <file> — Set timestamp using relative date expressions.
touch -d 'next Monday' reminder.txttouch -d '-2 days' <file> — Set timestamp to 2 days ago.
touch -d '-2 days' oldfile.txtModify Specific Timestamps
touch -a <file> — Update only the access time (atime).
touch -a data.logtouch -m <file> — Update only the modification time (mtime).
touch -m config.yamltouch -r <reference> <file> — Set timestamp to match another file's timestamp.
touch -r original.txt copy.txttouch -a -d '<date>' <file> — Set a specific access time.
touch -a -d '2026-06-01' data.csvCommon Patterns
touch .gitkeep — Create a placeholder to keep an empty directory in Git.
mkdir -p logs && touch logs/.gitkeeptouch -r <src> <dest> — Synchronize timestamps between files.
touch -r photo.jpg photo_edited.jpgfind . -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/.healthchecktouch -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
- GNU coreutils: touch invocation – official reference for every option
- Linux man page: touch(1) – the canonical manual page