My question is not so much a question of computer science as it is a question of etymology.
touch changes file access and modification times.
What does 'touch' stand for?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
It doesn't stand for anything; it's not an abbreviation or initialism. It's a verb.
touch a file, you're "putting fresh fingerprints on it", updating its last-modified date (or creating it if it did not yet exist).
As DopeGhoti says, updating the timestamps to the current time fits well with the semantic meaning of the English word. It's common to talk about "touching" data in memory to mean accessing it (e.g. "this function touches 2GB of data, so it trashes the CPU's caches"). The
touch(1) command exists to touch a file in a way that produces an effect on the metadata, without other effects.
It also has options to set the time/date metadata to something other than the current time, in which case the semantic meaning doesn't really apply anymore. (e.g.
touch -r reference_file /tmp/foo to set mtime and atime to be the same as the reference).
In case you were curious, the GNU coreutils
touch(1) implementation uses this sequence of system calls to update timestamps to the current time:
$ strace touch /tmp/foo ... open("/tmp/foo", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3 dup2(3, 0) = 0 close(3) = 0
O_CREAT achieves the create-if-missing behaviour. Omitting
O_TRUNC preserves the existing contents, like
>> /tmp/foo would.
dup2 updates the all three of mtime, atime, and ctime to the current time. (Just the
close() alone don't affect the timestamps).
To set the time to something other than "now", it does the same sequence, then uses
utimensat(0, NULL, ...) to set the times on the file referred to by stdout (since it duplicated the fd for that file to fd0).