touch — Create Files and Manipulate Timestamps
touch creates empty files and updates timestamps. Learn its options and the creative ways it's used in scripts and makefiles.
January 11, 20254 min read
LinuxFilesCommands
touch has two main jobs:
- Create empty files — if the file doesn't exist, touch creates it with zero bytes
- Update timestamps — if the file already exists, touch updates its access and modification times to now
The name comes from its original purpose — "touching" a file to update its timestamp, signalling to build tools like make that the file has changed.
Options
touch Options
| Option | Description |
|---|---|
-a | Update access time only |
-m | Update modification time only |
-c | Don't create file if it doesn't exist |
-d STRING | Set timestamp from human-readable string (e.g. "2024-01-15 10:30") |
-t STAMP | Set timestamp in [[CC]YY]MMDDhhmm[.ss] format |
-r FILE | Copy timestamp from another file |
Creating Files
touch file.txt # Create empty file (or update timestamp)
touch file1.txt file2.txt # Create multiple files at once
touch .hidden_file # Hidden file (starts with .)
# Pro: combine with brace expansion
touch index.{html,css,js} # Creates index.html, index.css, index.js
touch file{1..10}.txt # file1.txt through file10.txtUpdating Timestamps
Every file in Linux has two timestamps:
- Access time (atime) — last time the file was read
- Modification time (mtime) — last time the file content was changed
By default, touch updates both. Use -a or -m to update only one.
touch file.txt # Update both atime and mtime to now
touch -a file.txt # Update access time only
touch -m file.txt # Update modification time only
touch -c nonexistent.txt # Update if exists, don't create if not
# Set a specific timestamp
touch -d "2024-06-15 09:30" report.txt
touch -t 202406150930 report.txt # Same: YYYYMMDDhhmm
# Copy timestamp from another file
touch -r reference.txt target.txt # target gets reference's timeChecking Timestamps
# See modification time
ls -l file.txt
# See both access and modification time
stat file.txt
# File: file.txt
# Size: 0 Blocks: 0 IO Block: 4096 regular empty file
# Access: 2025-01-11 10:30:00
# Modify: 2025-01-11 10:30:00
# Change: 2025-01-11 10:30:00Quick Check
You run `touch existing.txt` on a file that already exists and has content. What happens?
Exercise
- Create a set of test files using brace expansion:
log-{jan,feb,mar}.txtandconfig.{yaml,json,toml} - Check their timestamps with
ls -l - Wait a few seconds, then touch one file
- Compare timestamps with
ls -lt(sorted by time) to see which was touched most recently