Frequently Asked Question
What does touch do, and when would I want to use it?
touch has two related jobs. If the named file does not exist, it creates an empty
one with default permissions. If the file does exist, it updates its access and
modification timestamps to the current time without altering the contents. Both
come from a single system call (utimensat(2)), which is also how it can backdate
a file with touch -d '2020-01-01' file or copy timestamps from another file with
touch -r reference target.
Day to day, the main uses are creating placeholder files (touch src/main.py before
you have anything to write into it), refreshing make targets so a build runs again,
and bumping the mtime on cache markers. touch -a updates only the access time,
touch -m only the modification time, and touch -c quietly does nothing rather
than create the file if it does not exist.