touch has two jobs. Its real purpose is to update a file's timestamps. Its handy side effect is that it creates an empty file if the name does not exist yet.
Creating empty files
$ touch notes.txt
$ ls -l notes.txt
-rw-r--r-- 1 pete pete 0 Nov 29 10:00 notes.txtThe size is 0 because nothing was written. You can name several files at once:
$ touch a.txt b.txt c.txtThe directory must already exist:
$ touch drafts/plan.txt
touch: cannot touch 'drafts/plan.txt': No such file or directoryExisting files are safe
If the file exists, touch leaves its contents alone and sets its access and modification times to now:
$ ls -l report.txt
-rw-r--r-- 1 pete pete 52 Jan 5 2025 report.txt
$ touch report.txt
$ ls -l report.txt
-rw-r--r-- 1 pete pete 52 Nov 29 10:01 report.txtThe size stays at 52. This is useful for tools that decide what to rebuild or back up by looking at modification times.
Choosing what to change
-cdoes not create missing files.-achanges only the access time.-mchanges only the modification time.
$ touch -c missing.txt
$ ls missing.txt
ls: cannot access 'missing.txt': No such file or directorySetting a specific time
-t takes a stamp in the form [[CC]YY]MMDDhhmm[.ss]:
$ touch -t 202601151430 report.txtThat means 15 January 2026 at 14:30. GNU touch on Linux also accepts a readable date with -d:
$ touch -d "2026-01-15 14:30" report.txtThe forms accepted by -d differ on BSD and macOS. Another option, -r, copies the times from a reference file: touch -r old.txt new.txt.
Use stat report.txt to see all the timestamps. You can practise on files in the files and links lab.
Try it
- Create three empty files with one command.
- Check their sizes with
ls -l. - Set one to an old date with
-t. - Run plain
touchon it and watch the date change.
Check your understanding
touch
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.