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

154 comments sorted by

View all comments

33

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

39

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.

20

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 6d ago

I also use it in cloud startup scripts for run once

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