touch Command Explained
touch is a small utility with a name that undersells what it actually does. Most people learn it as “the command that makes an empty file,” which is accurate but only half the story.
Creating an empty file
touch newfile.txt
ls -l newfile.txt
# -rw-r--r-- 1 colton colton 0 Jul 9 10:15 newfile.txt
If the named file does not already exist, touch creates it as a completely empty, zero-byte file with default permissions based on your current umask. This is the most common everyday use: quickly creating a placeholder file, a new script you are about to start writing, or a marker file a script checks for.
Updating timestamps on an existing file
touch existing-file.txt
stat existing-file.txt
# Modify: 2026-07-09 10:20:01
# (content is completely unchanged, only the timestamp moved)
If the file already exists, touch does not recreate or empty it. It simply updates the file’s recorded access and modification timestamps to the current moment, leaving the actual content byte-for-byte identical.
Why timestamp updates matter: build systems
make
# ... nothing to do, target is up to date ...
touch source.c
make
# recompiles source.c, because its modification time is now
# newer than the compiled output file
Tools like make decide whether a target needs rebuilding by comparing modification timestamps between source and output files. Running touch on a source file, without making any actual edit, is a common trick to force a rebuild when you know the build system’s cache is stale for some other reason, such as a changed compiler flag that the build tool cannot detect on its own.
Setting a specific date and time
# Human-readable date string
touch -d "2026-01-15 09:00:00" report.txt
# Compact numeric format: [[CC]YY]MMDDhhmm[.ss]
touch -t 202601150900 report.txt
# Copy the timestamp from another file
touch -r reference-file.txt target-file.txt
-d accepts a flexible, human-readable date string. -t accepts a more rigid but compact numeric format. -r copies the timestamp from an existing reference file onto the target instead of specifying a date directly, useful when you want two files to appear to have been modified at exactly the same moment.
Access time vs modification time
touch -a file.txt # update access time only
touch -m file.txt # update modification time only
touch file.txt # update both (the default)
stat file.txt
# Access: 2026-07-09 10:30:00
# Modify: 2026-07-08 14:00:00
# Change: 2026-07-08 14:00:00
Modification time (mtime) reflects when the file’s actual content last changed. Access time (atime) reflects when the file was last read or opened, regardless of whether anything inside it changed. By default, touch updates both timestamps to the current time. The -a and -m flags let you update just one, leaving the other exactly as it was.
Creating multiple files at once
touch file1.txt file2.txt file3.txt
# Combined with brace expansion
touch report-{jan,feb,mar}.txt
# creates report-jan.txt, report-feb.txt, report-mar.txt
Listing several filenames as separate arguments creates (or updates the timestamp of) each one in a single command, and combining this with shell brace expansion is a quick way to scaffold a batch of related placeholder files.
Common errors
touch /etc/newfile.conf
# touch: cannot touch '/etc/newfile.conf': Permission denied
touch missingdir/newfile.txt
# touch: cannot touch 'missingdir/newfile.txt': No such file or directory
The first error means you lack write permission on the target directory and likely need sudo. The second means the parent directory in the path does not exist yet; touch does not create missing parent directories the way mkdir -p does, so the directory has to already be there first.
Frequently Asked Questions
What does the touch command do?
touch has two related jobs. If the file you name does not exist, it creates a new, empty file at that path. If the file already exists, touch updates its access and modification timestamps to the current time without changing its contents at all.
Why would updating a file’s timestamp without changing its contents be useful?
Build systems and tools like make decide whether to rebuild something by comparing file modification timestamps. touch can force a file to be considered newer than it actually is, triggering a rebuild, without needing to make any real edit to the file. It is also used to mark files as recently accessed for scripts or monitoring tools that filter by modification time, and to quickly create placeholder files for testing.
How do I change a file’s timestamp to a specific date instead of the current time?
Use the -d flag with a date string, such as touch -d “2026-01-15 09:00:00” file.txt, or -t with a compact numeric format like touch -t 202601150900 file.txt. Both set the file’s timestamps to that exact specified date and time instead of the current moment.
What is the difference between access time and modification time?
Modification time (mtime) updates when a file’s actual content changes. Access time (atime) updates when a file is merely read or opened, even if nothing inside it changes. touch by default updates both. The -a flag updates only access time, and the -m flag updates only modification time, leaving the other timestamp untouched.
Can touch create multiple empty files at once?
Yes, list multiple filenames as separate arguments in one command, such as touch file1.txt file2.txt file3.txt, which creates all three (or updates their timestamps if they already exist) in a single invocation. This is a common pattern in setup scripts that need to scaffold several placeholder files quickly.
Does touch ever fail or refuse to run?
touch fails with a permission error if you do not have write access to the directory where you are trying to create a new file, or write access to an existing file whose timestamp you are trying to update. It also fails if the parent directory in the path does not exist, similar to how mkdir requires the parent path to already be present unless additional flags or a different command are used.