Same energy as Joan Cornella's comics
Programmer Humor
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
'Murica!
These are some weird looking dolph--- oh
Does anyone actually use touch
for its intended purpose? Must be up there with cat
.
TIL it's actually for changing timestamps.
Wtf. All these years I thought 'touch' was reference to Michelangelo's Creation of Adam.
That's beautiful, bro 🥲
The intended use of touch
is to update the timestamp right?
Yeah. It could just as well have issued a file not found error when you try to touch a nonexistent file. And we would be none the wiser about what we're missing in the world.
“Do one thing and do it very well” is the UNIX philosophy after all; if you’re 99% likely to just create that missing file after you get a file not found error, why should touch
waste your time?
Because now touch does two things.
Without touch, we could "just" use the shell to create files.
: > foo.txt
Touch does one thing from a “contract” perspective:
Ensure the timestamp of is
Systemd also does one thing from a contract perspective: run your system
Oh no.
:(
with this logic, any command that moves, copies or opens a file should just create a new file if it doesn't exist
and now you're just creating new files without realising just because of a typo
But this directly goes against that philosophy, since now instead of changing timestamps it's also creating files
You can pass -c
to not create a file, but it does go against the philosophy that it creates them by default instead of that being an option
EDIT: Looking closer into the code, it would appear to maybe be an efficiency thing based on underlying system calls
Without that check, touch just opens a file for writing, with no other filesystem check, and closes it
With that check, touch first checks if the file exists, and then if so opens the file for writing
We use it to trigger service restarts.
touch tmp/service-restart.txt
Using monit
to detect the timestamp change and do the actual restart command.
This is an interesting idea to allow non-root users to restart a service. It looks like this is doable with systemd too. https://superuser.com/a/1531261
I don't know anything about Linux but I do love touching cats
You would love Linux cli.
Touch is super useful for commands that interact with a file but don't create the file by default. For example, yesterday I needed to copy a file to a remote machine accessible over ssh so I used scp
(often known as "secure copy") but needed to touch
the file in order to create it before scp
would copy into it
Sorry, what?
cat
Ahhhhh, fuck. I'm quite noob with linux. I got into some rabbit hole trying to read the docs. I found 2 man pages, one is cat(1) and the other cat(1p). Apparently the 1p is for POSIX.
If someone could help me understand... As far as I could understand I would normally be concerned with (1), but what would I need to be doing to be affected by (1p)?
The POSIX standard is more portable. If you are writing scripts for your system, you can use the full features in the main man pages. If you are writing code that you want to run on other Linux systems, maybe with reduced feature sets like a tiny embedded computer or alternates to gnu tools like alpine linux, or even other unixes like the BSDs, you will have a better time if you limit yourself to POSIX-compatible features and options -- any POSIX-compatible Unix-like implementation should be able to run POSIX-compliant code.
This is also why many shell scripts will call #!/bin/sh instead of #!/bin/bash -- sh is more likely to be available on tinier systems than bash.
If you are just writing scripts and commands for your own purposes, or you know they will only be used on full-feature distributions, it's often simpler and more comfortable to use all of the advanced features available on your system.
Remember to confirm consent before touching.
You can only touch in places where you have permission to touch.
sudo touch woman
Iseif is not in the sudoers file. This incident will be reported.
As a Linux user, that is truly magical, and beautiful.
I'm way to used to doing nano file.txt
that I always forget about touch.
Although most times, if I create a file, it's to put something in it
If you need multiple files for testing a script or such: touch file{1..5}.txt
I do the opposite, I forget I can just create a file with nano. I run touch then open it with nano after to edit.
That's weird. Stop it.
Is there a command that's actually just for creating a new file?
Nope. If you open a nonexistent path and you have permissions to write to that directory, then that file is created.
How often do you actually need a blank file though? Usually you'd be writing something in the file.