14

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?

0

2 Answers 2

24

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

4
  • 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 Commented Mar 31, 2017 at 22:24
  • 1
    Short explanation, to the point and explaining exactly what it does. However it is generally used to create a file. Commented Mar 31, 2017 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". Commented Apr 3, 2017 at 14:44
  • 3
    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. Commented Feb 18, 2018 at 8:06
3

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.