Files and directories
touch
Update a file's timestamps, creating it empty if it does not exist.
touch [OPTION...] FILE...
touch sets a file's access and modification times to now. If the file does not exist, it
creates an empty one, which is what most people use it for.
With -d or -t you can set any time you like, and -r copies the times from another file.
That matters for anything that compares timestamps: make rebuilds targets older than their
sources, find -newer and -mtime select by age, rsync and backup tools skip files whose
time and size have not changed.
touch never changes a file's contents. To empty a file, use : > file or truncate.
Examples
Create an empty file
touch new.txt
ls -l new.txt
-rw-r--r-- 1 dev dev 0 Oct 31 20:21 new.txt
The file is created with size 0 and the current time.
Create several files at once
touch day{1..3}.md
ls day*
day1.md day2.md day3.md
Brace expansion produces day1.md day2.md day3.md; touch creates each one.
Bump the modification time of an existing file
ls -l todo.txt
touch todo.txt
ls -l todo.txt
-rw-rw-r-- 1 dev dev 62 Oct 24 21:28 todo.txt -rw-rw-r-- 1 dev dev 62 Oct 31 20:21 todo.txt
The content and size are unchanged; only the time moves to now. This is how you force
make to rebuild something, or make a file count as "recent".
Set a specific date and time
touch -d "2025-12-31 23:59" report.txt
ls -l --time-style=long-iso report.txt
-rw-r--r-- 1 dev dev 0 2025-12-31 23:59 report.txt
-d accepts the same free-form dates as date -d, such as "yesterday" or
"2 hours ago". Here it set a fixed timestamp on a new file.
Backdate a file
touch -d "3 days ago" old.txt
find . -maxdepth 1 -name '*.txt' -mtime +2
./todo.txt ./notes.txt ./file with spaces.txt ./old.txt
find -mtime +2 matches files modified more than two full days ago. The new old.txt
qualifies, and so do the fixture's own text files, which are about a week old.
Use -t with the classic stamp format
touch -t 202601150930.00 meeting.txt
stat -c '%y %n' meeting.txt
2026-01-15 09:30:00.000000000 +0000 meeting.txt
-t takes [[CC]YY]MMDDhhmm[.ss], the form that also works on BSD and macOS. stat
shows the full timestamp.
Copy timestamps from another file
cp notes.txt notes-copy.txt
touch -r notes.txt notes-copy.txt
ls -l notes.txt notes-copy.txt
-rw-r--r-- 1 dev dev 190 Oct 25 05:30 notes-copy.txt -rw-rw-r-- 1 dev dev 190 Oct 25 05:30 notes.txt
The copy got a new time from cp; -r sets it back to exactly what notes.txt has.
Update only files that exist
touch -c todo.txt missing.txt
ls todo.txt missing.txt
ls: cannot access 'missing.txt': No such file or directory todo.txt
-c (--no-create) touches todo.txt but does not create missing.txt, so ls can
still not find it.
Change only the modification time
touch -m -d "2026-01-01" todo.txt
stat --printf 'modify: %y\naccess: %x\n' todo.txt
modify: 2026-01-01 00:00:00.000000000 +0000 access: 2026-10-24 21:28:49.000000000 +0000
-m changes only the modification time; -a only the access time. The access time here is
left as it was.
Touching a file in a directory you cannot write to
touch /etc/new.conf
touch: cannot touch '/etc/new.conf': Permission denied
Creating a file needs write permission on the directory. Updating an existing file's time to "now" only needs write permission on the file; setting an arbitrary time needs ownership.
Common pitfalls
A typo creates a new empty file silently:
touch confg.jsondoes not warn. Usetouch -cwhen you only mean to update existing files.touchdoes not create directories;touch logs/2026/app.logfails iflogs/2026is missing. Runmkdir -pfirst.There is no option to set the creation (birth) time; most filesystems record it but only the kernel sets it.
GNU vs BSD and macOS
The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).
-dwith free-form dates like"3 days ago"is GNU. BSD/macOStouch -dtakes only an ISO-styleYYYY-MM-DDThh:mm:ss;-tworks the same on both.macOS adds
-Ato adjust times by an offset; on GNU use-dwith a relative date instead.
Options worth knowing
A selection, described in our own words. For the full list, see touch(1) or touch --help.
| Option | What it does |
|---|---|
-a | Change only the access time. |
-m | Change only the modification time. |
-c, --no-create | Do not create files that do not exist. |
-d, --date STRING | Use the time described by STRING instead of now. |
-t STAMP | Use [[CC]YY]MMDDhhmm[.ss] instead of now. |
-r, --reference FILE | Use FILE's times instead of now. |
-h, --no-dereference | Change a symlink's own times, not its target's. |
--time WORD | Change only atime (access, use) or mtime (modify). |
Related
statShow a file's metadata (size, permissions, owner, inode, timestamps), or print chosen fields in your own format.findWalk a directory tree and print, or act on, every file that matches a set of tests.mkdirCreate directories, optionally with all missing parents.truncateShrink or extend a file to an exact size, creating it if needed.datePrint the current date and time in any format, or convert and calculate dates.- Brace expansionGenerate lists of words with {a,b,c} and sequences with {1..10} and {01..10..2}, why {1..$n} does not work, and how braces differ from globs.