--- title: touch โ€” Create files and update timestamps date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: Command that creates an empty file or updates the modification time of an existing file. Used for deployment triggers and checks. tags: program, File and disk management, touch --- **๐Ÿ’ฌ "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 reload - `touch -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](https://games.aidebatehub.com/assets/touch-demo.png) 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.