touch — Create files and update timestamps
💬 "touch command"
touch creates an empty file, and if the file already exists, it only updates the modification time. It does not touch file contents.
In practice, it is often used as a configuration reload trigger or a deployment marker file.
- Concept: If the file does not exist, it is created as 0 bytes; if it exists, the access/modification time is updated to the current time.
- Left column: The created file name is generated as-is.
- Right column: For an existing file, the contents remain the same and only the Modify time changes.
- Specifying a time: You can specify the desired time with the -t and -d options.
Commonly used options
| Option | Description |
|---|---|
| -c | Update the timestamp only when the file already exists; do not create a new file |
| -t [[CC]YY]MMDDhhmm[.ss] | Set to a specific time |
| -d 'string' | Specify the time in a human-readable format |
| -a / -m | Update only the access time / only the modification time |
3 essential command combinations
touch /var/www/html/reload.txt— Update the file the app watches to trigger a reloadtouch -c /opt/app/current/public/index.php— Update the timestamp only if the file exists (prevents mistakes)touch -d '2026-10-18 02:00' /tmp/marker— Create a marker file with a specific timestamp
💬 "Show me the verification procedure in a rehearsal environment"
These are common situations on live production servers, organized in order.
Step 1 · Create a marker file
Create a file to record the deployment time.
touch /opt/app/releases/20261018/.deployed
Step 2 · Reload trigger
Trigger a reload in an environment with a configuration watcher.
touch /etc/nginx/.reload
Step 3 · Verification
Check that the timestamp was updated.
stat -c '%n %y' /etc/nginx/.reload
How it is used in practice
1. Zero-downtime reload trigger
Situation — PHP-FPM detects configuration changes by file timestamp.
touch /etc/php/8.3/fpm/php.ini
Result — The configuration watcher re-reads the file even without content changes.
Point — Useful when you need to force a reapply even if the configuration content has not changed.
2. Mark deployment status
Situation — After deploying to multiple servers, you need to check which server is up to date.
touch /srv/app/.deploy-20261018 && stat -c '%y' /srv/app/.deploy-20261018
Result — You can record each server's deployment time in a file and compare them.
Point — If monitoring reads the file existence/timestamp, you can automatically inspect deployment status.
Cautions
- The year format for -t is often confusing between two-digit and four-digit years. -d is easier to read for specifying times.
- Arbitrarily changing the timestamp of production files can confuse backup tools (incremental backups).
- If you mistype a path without -c, an empty file will be created in the wrong location.
Actual execution output
This is the result of creating a marker file and checking its timestamp.
!touch command execution result: empty file creation and timestamp check
Live production server
Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/touch.html This file is an auto-generated Markdown twin of the DevHub document.
AI Knowledge Hub
Visitor Comments