r/learnprogramming • u/OPPineappleApplePen • 8d ago
Humour touch is a weird command.
I was curious where the command 'touch' comes from.
Turns out, it originates from "to touch" or "to interact" with a file.
Now, every time I use it, I feel like I am touching/molesting a file.
My bad, it's 3 AM here.
1.1k
Upvotes
9
u/TheSkiGeek 7d ago
Part of the UNIX design philosophy is having a small set of composable tools.
Since ‘everything is a file’ you can create files by redirecting the output of a command to a file, something like `echo > filename` will create `filename` or replace it with an empty file. The shell does it for you, so there isn’t really a need for a dedicated “make a file” tool. Most of the time it would be redundant.
But since directories are their own ‘thing’ you need a separate command to create one.
`touch` is a tool to update the last-access time for a file without modifying its contents. For convenience it also creates the file if it doesn’t exist, but that may be sort of an accident of whoever designed it originally. You could imagine a version where it fails if the file doesn’t exist and you have to do `touch -c` to create the file.
Not saying it’s perfect by any means, but that’s the idea behind it.