Navigation and files

Command touch

Create file or update modification time

Linux · Bash examples · commands run on the selected server

When to use touch

Use touch to update file timestamps or create an empty placeholder. It does not erase the contents of an existing file, but changing timestamps can affect build tools and synchronization decisions.

Syntax

touch [OPTIONS] FILE…

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-c
Do not create the file if it is missing.
-r FILE
Take timestamps from another file.
-t MARK
Set the time in the format [[CC]YY]MMDDhhmm[.ss].

Usage examples

Create empty file

touch ./notes.txt

A missing notes file is created; an existing file keeps its contents while its timestamps change.

Update the time of an existing file

touch -c ./report.txt

Only an existing report is updated; a missing report is not created.

Copy timestamps

touch -r ./original.txt ./copy.txt

The copy receives access and modification timestamps taken from the reference file.

Notes and limitations

  • Existing file contents are preserved.
  • touch changes access and modification timestamps. Use an editor or a copy utility for other changes.

Common questions and troubleshooting

Will touch empty my existing file?

No. It changes timestamps rather than truncating contents. Shell redirection to a file is a different operation and can truncate it.

Why did a build or backup run again?

Those tools may use modification timestamps to detect changes. Updating a timestamp can mark unchanged content as newer.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man touch.