Home·Terminal commands

touch

Files and directories

Usage

touch [file]

Bumps a file's timestamps to now and creates it empty if it is missing; it never touches the contents.

Common flags

FlagMeaning
-aChange only the access time
-mChange only the modification time
-cDo not create the file if it is missing
-rCopy the timestamps from another file
-tSet an explicit time as [[CC]YY]MMDDhhmm[.SS]
-dGNU: set the time from a phrase such as -d yesterday

Examples

touch notes.md

Creates it empty, or just bumps the time.

touch -t 202401011200 report.pdf

Sets the time to noon on 1 Jan 2024.

touch -r a.txt b.txt

Gives b.txt the same times as a.txt.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does touch do?

Bumps a file's timestamps to now and creates it empty if it is missing; it never touches the contents.

Q. How do I type it?

touch [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man touch. This command sits under Files and directories.

Related commands

man page: man touch