Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Files and Directories

Linux touch command

Reference for the Linux touch command: create empty files, set access and modification times with -d, -t and -r, avoid creating files with -c.

touch does two jobs. If a file does not exist, it creates an empty one. If it does exist, it updates the file's access time and modification time, normally to the current moment, without touching the content.

With options you can set the times to any value, copy them from another file, or change only one of them. Build tools such as make rely on modification times, so touch is the standard way to mark a file as "changed" or to force a rebuild.

Terminal
touch [OPTION]... FILE...

Try it

Bash Creating files and setting dates

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Only access time, only modification time, and -c

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
touch [-acfhm] [-d DATE | -t STAMP | -r FILE] FILE...
Option Description
-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, --date=DATE Use a date string such as 2024-03-15 10:30, yesterday or @1700000000 (Unix seconds).
-t STAMP Use [[CC]YY]MMDDhhmm[.ss].
-r FILE, --reference=FILE Copy the times from FILE.
-h, --no-dereference Change the time of a symlink itself, not its target.

Returns: 0 on success; non-zero if any file could not be created or updated (for example "Permission denied" or "No such file or directory" when the parent directory is missing).

Usage notes

  • Without -a or -m both times are updated. With either flag, the other time keeps its value.
  • The inode change time (ctime) is always set to now and cannot be set by touch; it records that something changed.
  • Date strings are parsed by GNU date rules, so relative forms work: touch -d "2 days ago" file. Time zone matters: add UTC or set TZ for repeatable results.
  • Creating many files: touch file{1..100}.txt. The shell expands the braces before touch sees them.
  • Existing content is never truncated. touch file is safe on a file with data; : > file or > file empties it.
  • Permission rules: to set an arbitrary time you must own the file (or be root). If you only have write permission, you can update to "now", but not to a chosen time.
  • Timestamps are precise to nanoseconds on modern filesystems, but some formats (FAT) store only two-second resolution.
  • touch on a directory updates the directory's times; it does not create anything inside.
  • Makefile tip: touch -c target marks an up-to-date target without creating it by accident.