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
Usage examples
Create empty file
touch ./notes.txtA 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.txtOnly an existing report is updated; a missing report is not created.
Copy timestamps
touch -r ./original.txt ./copy.txtThe 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.