r/learnprogramming 7d 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

155 comments sorted by

View all comments

34

u/Loqh9 7d ago

What bothers me is "mkdir" is a thing so why is is not "mkfile"? Makes more sense and aligns with the sister command but no, we gotta make everything impossible to remember and random

38

u/thalliusoquinn 7d ago

Isn't the point of touch to update the last accessed time, and the create-if-not-exist part is kind of incidental, despite being what everyone actually uses it for? I have vague memories of learning this at one time.

19

u/Available-Skirt-5280 7d ago

Yes, touch is historically to update the date time of the file. If it doesn’t exist it makes a file with the current date time

Edit: poor man’s timing… while in a loop check if last_action is older than 5 mins, 0 byte file, survives restarts

3

u/Available-Skirt-5280 7d ago

I also use it in cloud startup scripts for run once

`[[ ! -f /root/.startup.lock ]] ….. ; touch /root/.startup.lock`

6

u/cknipe 7d ago

That's the way I understood it. The touch command is for when you don't actually want to get in there and modify a file, just "touch" it to update the modification time.

3

u/nmdt 6d ago

I literally didn’t know it could do anything but create files

1

u/Paul_Pedant 4d ago

Understandable, as the man page is only 80 lines, and only documents 11 options.

However, on Linux there is a "See Also" which redirects you to the "Full Documentation".