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 herenothing runs on your computer
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
| Option | What it does |
|---|---|
FILE | create it (empty) if it isn't there yet |
A B C | several files in one command |
-c | don't create anything, only touch files that exist |
Good to know
touchdoesn't create folders:touch logs/app.logfails iflogsdoesn't exist. Runmkdir -p logsfirst.- Careful with
>:echo "" > notes.txtDOES empty the file.touchnever does.