🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

touch Command

Beginner File Management man(1)

Create empty files or update file timestamps

👁 13 views 📅 Updated: Mar 15, 2026
SYNTAX
touch file.txt

What Does touch Do?

The touch command primarily creates empty files and updates file timestamps in Linux. While its original purpose is modifying access and modification times, it is most commonly used to quickly create new empty files.

touch can update either the access time (atime), modification time (mtime), or both. It can also set timestamps to a specific date and time, which is useful for testing, scripting, and managing backup systems that rely on file timestamps.

If the specified file does not exist, touch creates it as an empty file with zero bytes. This makes it the simplest way to create placeholder files, lock files, trigger files for automation, and flag files for deployment scripts.

Options & Flags

OptionDescriptionExample
-a Change only the access time touch -a file.txt
-m Change only the modification time touch -m file.txt
-c Do not create the file if it does not exist touch -c nonexistent.txt
-t Use specified timestamp [[CC]YY]MMDDhhmm[.ss] touch -t 202503140900 file.txt
-d Parse date string instead of timestamp format touch -d "2025-03-14 09:00" file.txt
-r Use the timestamp of a reference file touch -r original.txt newfile.txt
-h Affect symbolic link instead of referenced file touch -h symlink

Practical Examples

#1 Create an empty file

Creates a new empty file or updates the timestamp if it already exists.
$ touch newfile.txt

#2 Create multiple files at once

Creates three empty files in one command.
$ touch file1.txt file2.txt file3.txt

#3 Set a specific timestamp

Sets the modification time to January 1, 2025, midnight.
$ touch -t 202501010000 archive.tar.gz

#4 Use a readable date format

Sets the timestamp using natural language date parsing.
$ touch -d "last Friday" report.pdf

#5 Copy timestamp from another file

Sets destination.txt timestamp to match source.txt. Useful for synchronization.
$ touch -r source.txt destination.txt

#6 Create a trigger file for deployment

Many application servers watch for file changes to trigger restarts (e.g., Passenger).
$ touch /var/www/app/tmp/restart.txt

#7 Only update existing file timestamps

Updates timestamps of existing log files without creating new ones if they do not exist.
$ touch -c *.log

Tips & Best Practices

Creating structured files: Combine with brace expansion: touch src/{main,utils,config}.py creates three Python files at once.
Timestamps matter for backups: Tools like rsync and make use modification times to determine which files need updating. Be careful when manually changing timestamps.
Filesystem atime behavior: Many modern Linux filesystems mount with noatime or relatime for performance. The access time may not update as expected.

Frequently Asked Questions

What is the difference between touch and echo > file?
touch creates an empty file or updates timestamps without modifying content. echo > file creates/overwrites a file with a newline. touch is non-destructive on existing files, while > truncates them.
Can touch create files in a directory that does not exist?
No, the parent directory must exist. Use mkdir -p /path/to/dir && touch /path/to/dir/file to create both.
How do I see the timestamps that touch modifies?
Use stat filename to see all three timestamps (access, modify, change). ls -l shows modification time, and ls -lu shows access time.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →