touch

Create empty files from the terminal, several at once — and why touch never erases what is already inside.

>_ Try it: a simulated Linux, right here
Loading the terminal…

Examples

  • touch notes.txt
  • touch index.html style.css
  • ls -l
  • echo "buy milk" > notes.txt
  • touch notes.txt
  • cat notes.txt

How it works

touch FILE creates an empty file if it doesn't exist. If it does exist, touch only updates its time: the content stays exactly as it was.

It is the quickest way to make placeholder files (touch index.html style.css). To put text in a file, use echo "text" > FILE or an editor.

Syntax

touch [-c] FILE...

Options

OptionWhat it does
FILEcreate it (empty) if it isn't there yet
A B Cseveral files in one command
-cdon't create anything, only touch files that exist

Good to know

  • touch doesn't create folders: touch logs/app.log fails if logs doesn't exist. Run mkdir -p logs first.
  • Careful with >: echo "" > notes.txt DOES empty the file. touch never does.