Linux command list

touch command: create empty files and update timestamps

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying touch. Nothing here can touch your real files.
user@webterm:~/project$
 

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

Syntax

touch [options] file...

Names separated by spaces are all created.

Try it first

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.

It has two behaviours

What touch does depends on whether the target already exists.

TargetWhat happens
A file that does not existAn empty file is created
A file that already existsThe 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.

The option worth knowing

OptionWhat it does
-cDo 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.

When you actually reach for it

SituationWhat to type
Create a placeholder filetouch .gitkeep
Reserve a spot for a config filetouch config.yml
Force a rebuildtouch src/index.js
Only refresh files that existtouch -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.

Things that trip people up

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.

Practise it hands-on

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

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

Related commands

mkdir / ls / stat

Frequently asked questions

What does touch do?
If the file does not exist it creates an empty one; if it does exist it sets the modification time to now. The name comes from the second behaviour.
Does touch erase an existing file?
No. Only the timestamp changes; the contents stay. To empty a file, redirect into it with > filename instead.
What if I do not want to create the file?
Add -c. Missing files are left alone, so only timestamps of existing files are updated.
Can I create several files at once?
Yes. Separate the names with spaces, as in touch a.txt b.txt c.txt.
Can touch create a directory?
No. Use mkdir for directories; touch only makes files.