The touch command in Linux

touch was designed to update file timestamps, but in everyday use it is the standard way to create an empty file. If the file does not exist, touch creates it; if it does, touch simply updates its modification time and leaves the content untouched — which makes it safe to run on existing files.

How touch works

Every inode stores three timestamps: atime (last read), mtime (last content change) and ctime (last metadata change). touch is a small front-end over the system calls that set them — and when the file is missing, it creates it by opening with the O_CREAT flag, which is why "create an empty file" became its everyday job.

A subtlety worth knowing: you can set atime and mtime freely on your own files, but ctime cannot be set to an arbitrary value by anyone — the kernel updates it itself whenever the inode changes. Forensics and backup tools rely on exactly this property. And on modern systems, atime is often updated lazily (the relatime mount option) to spare disks a write on every read.

Syntax

touch [OPTIONS] FILE...

Common options

OptionWhat it does
-cDo not create the file if it does not exist (only update timestamps).
-aChange only the access time.
-mChange only the modification time.
-tSet a specific timestamp instead of the current time.

How to use touch: examples

$ touch notes.md

Create an empty file named notes.md (or update its timestamp if it exists).

$ touch index.html style.css app.js

Create several files at once.

$ touch file{1..5}.txt

Brace expansion creates file1.txt through file5.txt in one command.

Real-world use cases for touch

Marker files in automation

Long-running jobs often signal completion by creating an empty file: touch /tmp/backup.done. Other scripts or monitoring checks then just test for the file's existence — a primitive but bulletproof coordination mechanism used everywhere in ops.

Forcing a rebuild

Build tools like make decide what to rebuild by comparing timestamps. touch src/main.c updates the file's modification time without changing a byte, convincing make that it changed — the classic way to force one file to recompile.

Try touch yourself

This is a live sandbox with a small filesystem (documents/, notes.txt, backup.sh…). Nothing you do here can break anything — experiment freely. Try: touch notes.md

Pro tips and common mistakes

Frequently asked questions about touch

Does touch overwrite an existing file?

No. If the file exists, touch only updates its access and modification times. The content is never changed.

What is the difference between touch and echo > file?

touch creates an empty file and preserves existing content; echo "" > file creates the file too but truncates (empties) it if it already exists.

Related commands

mkdir

Create one or many directories, including whole nested paths with -p.

rm

Delete files and directories — and understand -r, -f and why there is no trash bin.

cat

Print file contents, number lines, and join multiple files together.

echo

Print text and variables, and write or append to files with > and >>.

Want to build real fluency? The interactive course takes you through touch and every other essential command with guided, checked exercises.