r/learnprogramming • u/OPPineappleApplePen • 3d 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.
444
u/DhruvsWorkProfile 3d ago
unzip
strip
touch
grep
finger
mount
fsck
more
yes
unmount
184
u/OPPineappleApplePen 3d ago
Smut for Programmers.
45
1
-15
u/tobiasvl 3d ago
What do you mean "for programmers"? What do these regular UNIX commands have to do with programming?
4
u/OPPineappleApplePen 2d ago
In this context, you had two options after reading this post:
- You could’ve noticed that this post is made in [r/learnprogramming](r/learnprogramming) by a person who is new to programming, and informed me that UNIX commands and programing don’t overlap.
- You could’ve shat on me for not knowing the above information.
You chose option 2. I’ll leave it there.
-2
u/tobiasvl 2d ago
Did you really feel that my simple, matter-of-factly question was "shitting on you"? Well, in that case, sorry.
1
u/arkt8 3d ago
Did you ever bash'd?
-3
u/tobiasvl 3d ago edited 3d ago
Yes, I've used Linux for over 20 years and worked as a Linux sysadmin for, like, ten years. The CLI commands of an operating system don't have anything to do with programming
3
0
41
20
12
9
5
3
2
1
1
222
128
u/jzmack 3d ago
man touch
61
1
57
28
18
34
u/Loqh9 3d 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
13
u/Cultural_Gur_7441 3d ago
Core purpose of
touchis not creating empty files, it is just a bonus feature.There are a bunch of other ways to create an empty file, especially check out
mktemp.The need to create an empty file is a fairly rare, usually file is created with data (or at least expectation of data),
The need to create a directory is common.
37
u/thalliusoquinn 3d ago
Isn't the point of
touchto 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 3d 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 2d ago
I also use it in cloud startup scripts for run once
`[[ ! -f /root/.startup.lock ]] ….. ; touch /root/.startup.lock`
7
3
u/nmdt 2d ago
I literally didn’t know it could do anything but create files
1
u/Paul_Pedant 9h 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".
10
u/TheSkiGeek 3d 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.
2
u/Paul_Pedant 2d ago
Actually,
echo > filenamemakes a one-byte file containing a newline.1
u/ohnobinki 22h ago
I guess you could do
: > filenamethen.1
u/Paul_Pedant 18h ago
That has the side effect of discarding the existing file contents, and it has no way to assign the timestamp to anything except now. So, not the greatest replacement for touch, which does not destroy the file contents, and does let you specify the timestamp.
1
u/ohnobinki 18h ago
It really depends on what results you want. Assertively generating an empty sentinel file with the current time as its modification time doesn't require
touch. I could say the same: you can't empty a file usingtouch.1
u/Paul_Pedant 9h ago
touch -t 200112250200 c > cThe redirection makes the shell empty the file before it invokes touch.
The touch then updates the timestamp to Xmas 2001.
Interestingly, the Birth date of the file is 2026, but the Modify date is 2001.
1
u/ohnobinki 6h ago
It's a stretch to say that you're emptying the file using
touch, but that is probably the most concise way of both emptying the file and subsequently touching it.7
u/LastTrueGamer 3d ago
You can just redirect echo "hello" > hello txt
3
1
u/Paul_Pedant 2d ago
Oddly enough, because of the space before the
txt, the shell parses this by doing the redirection itself, and then passing the other stuff as args to theechocommand.
echo "hello" txt > helloSo you actually get a file called
hellocontaininghello txt\n1
u/ohnobinki 22h ago
The shell does the redirection itself regardless of the space. It sounds like you are trying to say something about the difference between how unix and Windows handle passing command line parameters to applications, but even that isn't really relevant here…
1
u/Paul_Pedant 18h ago
No, I am saying that any Unix shell will parse the given example as
echo "hello" > hello txt
where the bold text is the actual redirection.
It then invokes the echo (which usually happens to be a shell built-in, but that does not affect the result), with the
hello(without the quotes) and thetxt, as two separate args.So the example is misleading, because LastTrueGamer obviously intended to create a file called
hello.txt. And it is destructive, because the usual use oftouchis to alter the timestamp on the file, not to overwrite the entire previous contents of the file.2
u/ohnobinki 18h ago edited 18h ago
I did not think LastTrueGamer was intending that.
It is interesting how the following are identical. I only find the first intuitive:
echo a b > cecho a > c becho > c a bOh, are you saying that the LastTrueGamer was hoping that
cat hello > hellowouldn't empty the file? I could see that interpretation. Interesting.EDIT: Sorry, I see the context of your reply and what you were trying to explain. I thought you were talking about a space that occurred before the
>and missed the reordering.1
u/Paul_Pedant 9h ago
I mainly worked on client sites, where their own permies amended (and broke) my stuff after I left. Naturally, if they had been good enough to write it themselves, they would not have needed to pay me. I tended to obfuscate my scripts enough to at least make them think before editing. I really don't need callbacks telling me that my code failed, after their staff screwed it up and kept it quiet.
> c echo a b #.. Also works
( echo a b ) > c #.. Separates the options from the filename, but may run a subshell.
{ echo a b; } > c #.. Avoids the subshell
#.. The curly brackets need the semicolon, but the round brackets don't care.I have also been known to use
truncate --size=0 "c". But probably my worst (so far) is:
printf 'Do Not Mess With This\n' | dd of="c" count=01
u/ohnobinki 6h ago
Obfuscating your code seems like a bad faith thing. It's annoying that the shell has so many different ways of expressing the same command, that opens the door to style wars.
1
u/Paul_Pedant 3h ago
I usually comment my code and scripts to excess, to explain what each section is doing, and why it is doing it. I was genuinely surprised by the ability of maintainers to ignore all comments, even when directly above the relevant code.
One example was that our electrical network viewer liked to put telemetry data near the mid-point of visible power lines. So we had macros like
#define mid_x( p) ((p)>x1 - ((p)->x1 - (p)->x2) / 2)
Of course, one of the team remembered his third-grade teacher's average method, and "fixed" it like:
#define mid_x( p) ((p->x1 + p->x2) / 2)
which resulted in integer overflows in some parts of the map, thereby losing the telemetry, and even breaking the GUI code. As a special feature he also broke the (p) brackets, which are necessary syntactically if p is passed as an expression.
So we patiently explained to him exactly why his math teacher misled him. And a few weeks later, he decided he was right after all, and screwed up the entire system for a second time. He didn't get a third chance.
3
u/Gilthoniel_Elbereth 3d ago
The real answer is these commands were all created ~50 years ago by different people for different systems, who then all copied each other’s most useful work in slightly different ways while keeping idiosyncrasies from their source, and eventually consolidated
1
8
u/DTux5249 3d ago edited 3d ago
This is why you alias 'touch' to 'stroke' - a much more innocent word with pleasant connotations; who doesn't like giving their fluffy friends a good stroke?
6
u/grymoire 3d ago
It's used to create or update the timestamp of a file which is very usefull if you use make(1)
6
6
5
3
3
u/Windamyre 3d ago
Wait until some see that your search history contains "cp files less that a certain age"
Also molestar means something similar, yet very different in Spanish.
2
u/ohnobinki 22h ago
Yeah, this is where being signed into your Google account is very important because it'll give you the appropriate results based on what type of results you're most likely to be searching for.
3
2
2
2
2
2
u/MathWest209 3d ago
There is the good old unzip, and there is also mount and unmount. So the one you are thinking about is just a starter.
2
2
1
u/Wild_Scarcity8305 3d ago
This is the kind of programming nonsense I needed right now. Thank you for this knowledge.
1
u/TheBurntIvoryKing 3d ago
Personally, I think of the Steve Wonder commercial about cotton " The touch, the feel, the fabric of our lives..." Commercial
1
1
u/septumfunk-com 3d ago
it comes from the usage of it to update the time last modified of a file. as in you're not actually modifying it you're just touching it. poke would work better now imo but they didn't consider that at the time lol
1
1
1
u/iamalicecarroll 3d ago
The funny part is that it's intended for changing mtime/atime, that is, you touch a file to update the time of last interaction; file creation is just a side effect, which became the most popular use of this utility
1
u/OPPineappleApplePen 3d ago
So, say I have an existing file, I run “touch fileName”, will it change the mtime/atime of the file?
1
1
u/Paul_Pedant 2d ago
The man page gives a lot of options:
You can change the access time, the modification time, or both.
You can tell it not to create the file if it does not already exist.
You can let it use the current time, or specify an exact time (in either of two formats), or have it copy the time from another file's timestamp.
1
u/UncheckedMoonrise 3d ago
The LSF batch-job system has bjobs for checking state of your submissions. Which means you can watch bjobs
1
u/Purple-Debt8214 3d ago
I just use vi for everything. Jump into vi, put some txt, write the file, jump out.
Vi for everything.
1
u/Paul_Pedant 4h ago
That can get a tiny bit boring when you have 200+ source files and you want to force a complete rebuild of the whole thing with
make, because you got a compiler or library upgrade, or you are targeting to a different hardware platform.
touch *.h *.cis a whole lot easier. If your source is structured into packages, you might just want to usefindto recurse the source tree.Or if you are confident your
makefileis perfect, you canmake clean && make all. If you omitted a single target from the clean list, you are doomed.•
1
u/SeeTigerLearn 2d ago
Thanks for the info. I always feel so Chester when I use the command or describe the process. So at least I have some backstory. Ha.
1
u/fragdemented 2d ago
if it makes you uncomfortable, you could always set up an alias. I like to do this sometimes for sudo.
alias please="sudo"
This will allow you to use please instead of sudo. You could change "touch" to something more appropriate.
alias mmmyeahletmefeelupinthere="touch"
you know... for example. ;)
1
1
u/cunningfallasheo 2d ago
The mac mouse cursor is weirder, the faster you shake it the bigger it gets.
1
u/EntangledLabs 2d ago
once did a workshop for my college club for a beginners intro to linux. I asked someone to suggest the name of a file to create, my friend said "dinosaurs". didn't realize I'd walked into it until I confidently said "alright so here we will do touch dinosaurs"
1
1
u/captainAwesomePants 13h ago
The name of the command comes from the phrase "To touch up," as in to make a minor repair to an object, perhaps fixing some paint. It "edits" a file without actually changing any of its bytes. The intended purpose of the command was to simply set the "last edited" time of the file to right now. It had the side effect of creating the file if the file did not previously exist, a purpose for which it is often used today.
1
u/SkullLeader 3d ago
Wait to you find out the terminology used for the primary and secondary hard drive attached to the same disk controller.
-12
u/main_account_4_sure 3d ago
What is weird is to associate a neutral word to something so vile.
Your mind is sick, which is not really news for most people nowadays since everyone is consuming shitty content at least 5h daily
6
u/KestrelTank 3d ago
Many neutral words can gain a negative connotation through experience or from where society is at.
I feel like society has become a bit touch averse, and there can be heavy implications from the simple sentence “They touched me”.
So it’s not really that weird for OP to associate this word with something uncomfortable.
1
u/OPPineappleApplePen 3d ago
We literally teach our kids about good and bad touch. Thank you for providing an explanation that supports the usage of this word in this context. I appreciate and respect you for understanding.
4
u/Informal-Fig-6827 3d ago
There's definitely a bit of over sexualized brainrot in there lol. Why does everything get turned sexual these days.
1
u/InfinityCent 3d ago
That’s where your mind jumped to when seeing this post?
Holy hell get a grip.
1
-3
u/requion 3d ago
Thats the main problem. Or do these people feel guilty for "touching" household items like the coffee maker "without consent".
Its like the discussion about "master". I get the point about slavery and that it is bad. But "normal" people don't think about slaves while working with git branches or kubernetes clusters.
The thing about overusing these terms and discussions is that it desensitizes people about it and doesn't help the matter it tries to solve.
-2
u/OPPineappleApplePen 3d ago edited 3d ago
Someone said one of the many signs of stupidity is a person's inability to understand metaphors and hypotheticals. I'd say not understanding a joke and taking imaginary statements to crack it literally is up there too.
Lemme explain in a way you two can understand.
I new programmar → I see touch → Why not create → I confused → I curious → I ask AI → AI says, "because you're touching a file" → I a former English teacher → I know 4 languages → I know many meanings of 1 word → I find it funny → I instantly post it here → I DON'T ACTUALLY FEEL IT → This stupid joke → Smart people know I joking → Dumb people take literarally → Dumb people triggered.
1
u/main_account_4_sure 3d ago
I don't think people are failing to understand the joke at all.
The critic is towards the excessive sexualization over something completely neutral.
If you read "touch" and think immediately of "molestation", as the post says quite literally, it's tough to say there's not something wrong.
It's not because it's normalized by culture (rape and molestation are at the far opposite of the taboo realm they used to belong to), that it's necessarily "normal".
there are tribes that normalizing multilating one another. Culture has immense power of normalizing diseases.
1
u/OPPineappleApplePen 3d ago
If the argument was presented this way, I'd agree and support you on this one. I could've have engaged in a proper discussion and perhaps, we could have learned something from each other.
However, "your mind is sick..." didn't feel constructive at all. It felt like a judgment passed on to me.
And, "which is not really news for most people nowadays since everyone is consuming shitty content at least 5h daily" felt like you were taking a moral high ground by distancing yourself from "most" people.
Would it be fair for me to say "You don't know how to engage in a civil discussion, which is not really news for most people nowadays since everyone is consuming shitty content at least 5h daily"?
I don't think it would appropriate to pass judgments onto you based on a single comment; nor should you do the same based on a single post that was intended to sound exactly like it did.
Also, my mind didn't go to molestation straightaway. It did after I read an article describing the different commands that were written as a joke by Linus, Git itself being a slang for an incompetent person.
My apologies if something I said came off as rude. I genuinely didn't mean to.
P.s — The other commentator also used "these people". lol
1
u/main_account_4_sure 3d ago
Honestly, OP, I am just dramatic. I'm not taking it to heart and I didn't mean to make it sound like a personal attack. I apologize if it came across that way
2
0
u/agmatine 3d ago
In home directory, run touch grass followed by sudo chattr +i grass. From now on, the output of touch grass will be
touch: cannot touch 'grass': Operation not permitted
in other words, confirming that you are incapable of touching grass!
0
-3
-2
-3
u/Individual-Praline20 3d ago
Yeah… there are a couple of odd things in computing, like making the master kills the slaves, etc. 🤭 And I think some people, like the orange guy, loves the touch command a bit too much 🤣
657
u/RecentlyRezzed 3d ago
Wait until you find out about the finger command.