touch creates an empty file, or updates the timestamp of one that already exists. Learn when each behaviour applies, by running the commands in a real terminal in your browser.
Updated: 2026-09-04
touch [options] file...
Names separated by spaces are all created.
The terminal on this page holds README.md and a logs/ directory.
$ ls
logs/ README.md
$ touch NOTES.md
$ ls
logs/ NOTES.md README.md
NOTES.md now exists as an empty file. Like most creating commands, touch prints nothing on success.
What touch does depends on whether the target already exists.
| Target | What happens |
|---|---|
| A file that does not exist | An empty file is created |
| A file that already exists | The timestamp is set to now, and the contents are kept |
$ touch README.md
README.md already existed, so nothing was recreated: only its timestamp moved. The contents survive, which is the crucial difference from > README.md.
| Option | What it does |
|---|---|
-c | Do not create anything; only update timestamps of files that exist |
$ touch -c MISSING.md
$ ls
logs/ NOTES.md README.md
MISSING.md was not created.
| Situation | What to type |
|---|---|
| Create a placeholder file | touch .gitkeep |
| Reserve a spot for a config file | touch config.yml |
| Force a rebuild | touch src/index.js |
| Only refresh files that exist | touch -c filename |
Updating a timestamp is how you nudge tools that decide what to rebuild by comparing modification times, such as make. It lets you trigger a rebuild without changing a single character.
It does not erase anything.
Running touch on an existing file destroys nothing. To empty a file, use > filename. Confusing the two is how people delete work they meant to keep.
A missing parent directory is an error.
$ touch a/b.txt
touch: cannot touch 'a/b.txt': No such file or directory
a does not exist. Run mkdir -p a first.
It cannot make directories.
touch only creates files. Use mkdir for directories.
Terminal for Beginners
Learn basic commands

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the course