My question is not so much a question of computer science as it is a question of etymology.

The command touch changes file access and modification times.

What does 'touch' stand for?


It doesn't stand for anything; it's not an abbreviation or initialism. It's a verb.

When you touch a file, you're "putting fresh fingerprints on it", updating its last-modified date (or creating it if it did not yet exist).

  • Oohh. It was not intuitive to me that the verb 'touch' would be a good match for the role of the command touch but I get it now. Thanks
    – Remi.b
    Mar 31 '17 at 22:24
  • 1
    Short explanation, to the point and explaining exactly what it does. However it is generally used to create a file.
    – Xorifelse
    Mar 31 '17 at 23:30
  • It's certainly frequently used for that, but its own self-description on its own man page is: "touch -- change file access and modification times".
    – DopeGhoti
    Apr 3 '17 at 14:44
  • 2
    I suppose one could ask "when was the file last touched?" to mean when it was last changed (e.g. by writing to it), or "the file hasn't been touched in years". The touch command simulates the effect, hence the name.
    – Ned64
    Feb 18 '18 at 8:06

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).

Somewhat related:

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

open with 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 open()/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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.