this post was submitted on 17 Mar 2024
384 points (100.0% liked)

Programmer Humor

24761 readers
893 users here now

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

founded 2 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 35 points 1 year ago (1 children)

images-2

Same energy as Joan Cornella's comics

[–] [email protected] 10 points 1 year ago
[–] [email protected] 33 points 1 year ago

These are some weird looking dolph--- oh

[–] [email protected] 28 points 1 year ago (29 children)

Does anyone actually use touch for its intended purpose? Must be up there with cat.

[–] [email protected] 35 points 1 year ago (1 children)
[–] [email protected] 30 points 1 year ago (2 children)

Wtf. All these years I thought 'touch' was reference to Michelangelo's Creation of Adam.

[–] [email protected] 22 points 1 year ago

That's beautiful, bro 🥲

[–] [email protected] 6 points 1 year ago (3 children)
load more comments (3 replies)
[–] [email protected] 19 points 1 year ago* (last edited 1 year ago) (1 children)

The intended use of touch is to update the timestamp right?

[–] [email protected] 22 points 1 year ago (1 children)

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.

[–] [email protected] 6 points 1 year ago (3 children)

“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?

[–] [email protected] 14 points 1 year ago (1 children)

Because now touch does two things.

Without touch, we could "just" use the shell to create files.

: > foo.txt
[–] [email protected] 14 points 1 year ago (1 children)

Touch does one thing from a “contract” perspective:

Ensure the timestamp of is

[–] [email protected] 15 points 1 year ago (2 children)

Systemd also does one thing from a contract perspective: run your system

[–] [email protected] 4 points 1 year ago
load more comments (1 replies)
[–] [email protected] 6 points 1 year ago (1 children)

But this directly goes against that philosophy, since now instead of changing timestamps it's also creating files

[–] [email protected] 6 points 1 year ago* (last edited 1 year ago)

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

[–] [email protected] 11 points 1 year ago (1 children)

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.

[–] [email protected] 6 points 1 year ago (1 children)

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

load more comments (1 replies)
[–] [email protected] 6 points 1 year ago (1 children)

I don't know anything about Linux but I do love touching cats

[–] [email protected] 5 points 1 year ago

You would love Linux cli.

[–] [email protected] 6 points 1 year ago* (last edited 1 year ago) (1 children)

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

[–] [email protected] 9 points 1 year ago

Sorry, what?

load more comments (24 replies)
[–] [email protected] 28 points 1 year ago (1 children)

Remember to confirm consent before touching.

[–] [email protected] 41 points 1 year ago (1 children)

You can only touch in places where you have permission to touch.

[–] [email protected] 14 points 1 year ago (1 children)
[–] [email protected] 25 points 1 year ago (1 children)

Iseif is not in the sudoers file. This incident will be reported.

[–] [email protected] 7 points 1 year ago (2 children)
[–] [email protected] 17 points 1 year ago

As a Linux user, that is truly magical, and beautiful.

[–] [email protected] 13 points 1 year ago (3 children)

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

[–] [email protected] 6 points 1 year ago (1 children)

If you need multiple files for testing a script or such: touch file{1..5}.txt

load more comments (1 replies)
[–] [email protected] 5 points 1 year ago (1 children)

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.

[–] [email protected] 9 points 1 year ago

That's weird. Stop it.

load more comments (1 replies)
[–] [email protected] 6 points 1 year ago (11 children)

Is there a command that's actually just for creating a new file?

[–] [email protected] 6 points 1 year ago

Nope. If you open a nonexistent path and you have permissions to write to that directory, then that file is created.

[–] [email protected] 4 points 1 year ago (5 children)

How often do you actually need a blank file though? Usually you'd be writing something in the file.

load more comments (5 replies)
load more comments (9 replies)
load more comments
view more: next ›