The Linux touch command is one of the simplest yet the most powerful tools used to create new empty files or update the timestamps of already existing ones. It is an essential tool that should be a part of your toolkit as a Linux user.
Unlike editors that open a file for quick setup tasks, the Linux touch command creates an empty file that is perfect for quick setups. It can also modify the access permissions and modification times of files without altering their data, which is especially useful in building systems, backups, and automation workflows.
Whether you are a system administrator, developer, or a beginner who is learning commands, understanding the touch command in Linux is definitely beneficial for you.
Basic Syntax of touch
The general syntax of the touch command is:
touch [options] filename(s)
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
Explanation:
- touch: The command itself.
- [options]: Optional flags to modify behavior.
- filename(s): One or more file names you want to create or update.
Most Common Usage:
touch file.txt
- If file.txt doesn’t exist, it will be created as an empty file.
- If it already exists, the access and modification timestamps will be updated to the current time.
Creating New Empty Files
If you want to create a new empty file using touch, use the following command line:
touch newfile.txt
If newfile.txt does not already exist, touch will create it with zero content. If it does exist, the timestamp will get updated.
Updating Timestamps on Existing Files
If a file is already in the system, running touch command would update its access and modification times to the current timings. You can use this line:
touch existingfile.log
This is an extremely powerful tool for automation or to build scripts that rely on file timestamps to trigger actions.
Using touch with Multiple Files
You can create or update several files simultaneously by listing them:
touch file1.txt file2.txt file3.log
If any of these files don’t exist, they’ll be created. If they do exist, only their timestamps will be updated.

Changing Access and Modification Times with touch
The Linux touch command is not just used for creating files, but also for manipulating file timestamps. You can use options like -a, -m, and -t to customize timings and set values.
Using the -a Option (Access Time Only)
The -a flag updates the access time only, leaving the modification time unchanged.
touch -a file.txt
This is useful if you want to simulate a file being accessed without modifying its content.
Using the -m Option (Modification Time Only)
The -m flag will update the modification time without altering the access time.
touch -m file.txt
Great for tricking building tools or processes that are dependent on mtime.
Using the -t Option (Set Custom Timestamp)
The -t option lets you set a specific timestamp in the format:
[[CC]YY]MMDDhhmm[.ss]
Example:
touch -t 202504101200.00 file.txt
This sets:
- Year: 2025
- Month: April (04)
- Day: 10
- Time: 12:00:00 PM
Creating Files with Specific Timestamps
To set a specific timestamp when you are creating a file, you can use the -t option.
touch -t [[CC]YY]MMDDhhmm[.ss] file.txt
Example:
touch -t 202312311159.59 log.txt
This sets the timestamp of log.txt to December 31, 2023, at 11:59:59 AM.
Preventing File Creation (Update Only)
If you only want to update the timestamps in an existing file and avoid creating new files, you can use the -c or – – no – create flag.
touch -c existingfile.txt
Using touch in Scripts and Automation
The touch command is often used in scripts for tasks like:
- Creating Marker Files
touch /tmp/script_started
- Controlling Cron Jobs
if [ -f /var/run/task.lock ]; then
echo “Task already running”
else
touch /var/run/task.lock
# Run your task
rm /var/run/task.lock
fi
- Triggering File Watchers
Some programs (like build tools or daemons) watch for file changes — touch can trigger those watchers without editing the file:
touch config.yaml
Linux touch Command vs. Other File Creation Methods
Command | Creates Empty File | Opens Editor | Updates Timestamps | Script-Friendly |
touch file.txt | ✅ | ❌ | ✅ | ✅ |
> file.txt | ✅ (or truncates file) | ❌ | ❌ | ✅ |
echo “” > file.txt | ✅ | ❌ | ❌ | ✅ |
nano file.txt | ❌ (requires input) | ✅ | ❌ | ❌ |
vim file.txt | ❌ (requires input) | ✅ | ❌ | ❌ |
Common Errors and Troubleshooting
The touch command is straightforward, but some common errors can trip up new users. Here’s a quick guide to what might go wrong and how to fix it:
- Permission Denied
touch: cannot touch ‘file.txt’: Permission denied
Cause: You don’t have write permission in the current directory.
Fix: Use sudo if appropriate, or switch to a directory where you have write access:
sudo touch file.txt
- Missing File Operand
touch: missing file operand
Cause: You didn’t specify a file name.
Fix: Add the filename after the command:
touch newfile.txt
- No Such File or Directory
touch: cannot touch ‘dir/file.txt’: No such file or directory
Cause: The specified directory path doesn’t exist.
Fix: Create the directory before using touch:
mkdir -p dir && touch dir/file.txt
- File Not Visible
Symptom: File seems to be created but isn’t showing up.
Cause: The file name starts with a dot, making it a hidden file (e.g., .hiddenfile).
Fix: Use ls -a to see hidden files:
ls -a
Wrapping Up – Linux touch Command
The Linux touch command is one of the important tools for efficiency in the Linux system. Understanding the thought behind the command and learning it’s syntax will help you with file creation and modification of timestamps.