The touch command updates file access and modification timestamps, and can create files that do not already exist.
It is commonly used in build automation, file initialization, and timestamp management.
Overview
Use touch when you need to:
- Create empty files quickly
- Update modification/access times to current time
- Apply specific timestamps to files
- Align timestamps between files
Syntax
touch [options] file...
Common forms:
# Create file if it does not exist, else update timestamp
touch notes.txt
# Update timestamp without creating a new file
touch -c existing.txt
# Set explicit timestamp
touch -t 202606301200.00 report.txt
Common Options
| Option | Purpose | Example |
|---|---|---|
-a |
Change access time only | touch -a file.txt |
-m |
Change modification time only | touch -m file.txt |
-c, --no-create |
Do not create file if missing | touch -c maybe.txt |
-d STRING |
Parse date/time string (GNU) | touch -d '2026-06-30 12:00' file.txt |
-t STAMP |
Use [[CC]YY]MMDDhhmm[.ss] format | touch -t 202606301200 file.txt |
-r FILE |
Use timestamps from reference file | touch -r src.txt dst.txt |
Timestamp Basics
touch manages:
atime: last access timemtime: last modification time
By default, both are set to current time (or file is created if missing).
Examples
# Create one empty file
touch todo.md
# Create multiple files at once
touch file1.txt file2.txt file3.txt
# Update only modification time
touch -m app.log
# Update only access time
touch -a app.log
# Set timestamp from explicit date/time (GNU)
touch -d '2026-06-30 08:30:00' report.csv
# Copy timestamps from another file
touch -r source.bin target.bin
# Do not create missing files
touch -c maybe-missing.txt
Build and Automation Use Cases
Trigger make-style rebuild behavior by changing mtime:
touch src/main.c
Initialize expected marker files:
mkdir -p .state
touch .state/initialized
Safe Usage Guidelines
- Use
-cin scripts when file creation is not desired. - Prefer explicit timestamps (
-tor-d) for reproducible workflows. - Verify timezone expectations in CI environments.
- Do not rely on timestamps alone for security-sensitive logic.
Troubleshooting
touch: cannot touch 'file': No such file or directory
Cause: Parent directory does not exist.
Fix:
mkdir -p parent
touch parent/file.txt
Timestamp did not change as expected
Possible causes:
- Filesystem mount behavior (atime policies)
- Option used (
-avs-m) - Incorrect date format
Fixes:
- Validate with
ls -landstat - Use explicit options and known timestamp format
File was created unexpectedly
Cause: Default behavior creates missing files.
Fix:
touch -c file-that-may-not-exist
Notes
touch is lightweight but important for deterministic automation.
Timestamp semantics can vary slightly by filesystem and operating system.
For command details and implementation-specific behavior, run:
man touch
touch --help