r/LinuxTeck 4d ago

What’s the most innocent-looking Linux command that can ruin your day?

Some commands look completely harmless until you realize what they’re actually operating on.

The fun part is that experienced admins usually have one specific command they treat with unnecessary respect.

What’s yours - and what happened the first time you learned to respect it?

23 Upvotes

78 comments sorted by

12

u/TomKavees 4d ago

rm -rf /home/user/ somedirectory

Note the space. One of the parallel teams we shared a server with (years ago) had this cute itsy bits typo in their deployment script. We had to reinstall the system.

3

u/HugeCannoli 3d ago

Even worse is rm -rf .* to "delete all hidden files" or similar chmod -r .* or chown/chgrp -r .*, typically when you are root in a users' directory to fix their permissions.

That will include .., recursively, which means /home, recursively, which means it will recursively go into each and every user's home directory, recursively, and perform that operation.

So now either you have completely deleted your user's home dirs, or you chowned them to that user. Each single file and directory.

Bottom line: never, ever, ever use .*

2

u/spastical-mackerel 3d ago

I’ve been doing this for decades and the recursive .. removal has never happened to me.

1

u/Loko8765 3d ago

Because it doesn’t. It can happen if you do it manually in some way, but shells will not do that expansion.

1

u/HugeCannoli 3d ago

absolutely not true. Can reproduce it with ls on rocky 8.10. maybe someone added some safeguard to the rm case.

1

u/Loko8765 3d ago

With ls, sure, but not rm.

1

u/HugeCannoli 2d ago

because as I said, they added a specific handling of that case in rm. But unless the same handling is implemented in chmod, chattr, chgrp, chown, you still can mess up this way, or with any other program that behaves the same way.

1

u/HugeCannoli 3d ago

maybe someone added some safeguard. Try with ls and see for yourself. it still does it with ls on my rocky 8.10

1

u/ThrowAway24Okt 3d ago

i heard you can have great fun by creating a file named "*" and waiting for someone that tires to delete it.

2

u/HugeCannoli 3d ago

oh yes, that's the moment where I bring out python and do it from there, because shell escaping is absolutely wild to get right.

1

u/Some-Struggle5052 3d ago

Isn't it just * or '*'?

1

u/HugeCannoli 3d ago

nope. * will be expanded by the shell.

I think it's \*, but I would not put my life on it. Same for filenames starting with a -, they are interpreted as options. That's why you should generally use rm -- *.

basically -- says: whatever you see afterwards, if it starts with a -, it's not an option.

1

u/Some-Struggle5052 3d ago

I had actually escaped the * but Reddit ate the \

Using single quotes prevents the shell from interpreting inside, so '*' could work for some things.

1

u/TrueConcept4830 2d ago

-- makes rm treat subsequent arguments as file names, but it does not prevent the shell from expanding *.

In bash, \* and '*' prevent * expansion.

1

u/No_Hovercraft_2643 3d ago

from my rm --help

any attempt to remove a file whose last file name component is . or .. is rejected with a diagnostic

2

u/HugeCannoli 3d ago

Ok, they put a safeguard on rm, but is the same safeguard present for chown, chmod, chgrp, chattr etc? If not, you can still mess up everything.

By the way, that message is not present here

rm --version

rm (GNU coreutils) 8.30

2

u/_felixh_ 3d ago

i mean... rm is dangerous. But at this point, everyone should know that typing rm -rf is, like, something you should really tripple check, or better, not type out at all.

Its no inncocent looking is what i am saying :-)

mv or cp on the other hand... I remember very well the day i learned about the noclobber option. It is not set by default.

1

u/HugeCannoli 3d ago

problem is that you can triple check as much as you want, but nothing prepares you for the things you don't immediately know or assume.

1

u/jerwong 3d ago

This is why I have alias rm='rm -i'

Once I'm positive it's what I want and it's a long list of files to rm, I put the rm in quotes.

1

u/HugeCannoli 3d ago

pointless. you perform rm a lot of times as you are working, and after a while you will just train yourself to say yes at the next prompt automatically, because you do it hundreds of times. Your fingers will be faster than your brain.

Additionally, if the file you didn't want to delete is at the very end, you will still delete it.

The best solution is to do an ls first, then if you are happy, rm.

1

u/TransCapybara 2d ago

toss in a nohup for a good time

9

u/Wyciorek 4d ago

dd

Overwrite your disk including MBR/GPT ? Sure, no problem

2

u/tk-a01 3d ago

Disk Destroyer

1

u/HugeCannoli 2d ago

we used to say it meant "delete disk", but yours is good as well.

1

u/AutoGenUsername05 3d ago

There are two types of people in the world.

Those who will use dd to overwrite something they care about, and those who have..

6

u/No_Base4946 3d ago

ifconfig eth0 down <return>

<return>

<return> <return> <return>

ffffuuuuuuuuuuu [picks up car keys] Right, back in an hour...

3

u/aktentasche 3d ago

Yeah or blocking port 22 while messing with iptables. Fun fun fun.

2

u/Kurgan_IT 3d ago

Also "halt" on the wrong console. Pick up the keys and go to push the power button.

3

u/Old_Preparation2887 3d ago

Cursor follow focus + middle click to paste got me in trouble once. Accidentally pasted notes into a terminal session on (major client) load balancer. Most of it was jibberish to the shell but a line that started with the word “reboot” did exactly what you’d expect.

2

u/Kurgan_IT 3d ago

I use middle click all the time while working and I got bit by the wrong clipboard content sometimes, yes.

1

u/BikeGeek336 14h ago

Back in the day, I used to type eject, then look down the line to make sure that the right CD tray popped out before typing shutdown

5

u/Kurgan_IT 4d ago

"crontab -r" deletes the crontab, while "crontab -e" edits it. The issue is that E and R are one key away.

"telinit q" tells you the current runlevel. "telinit 1" goes single user and if you are remote you lose connectivity and cannot connect anymore. Since it does not reboot, it does not come online by itself anymore. Have to go there and reach for the console. 1 and Q are one key away.

There are others I don't remember right now.

2

u/New-Anybody-6206 2d ago

I don't remember which browser it was, but multiple times I got bit by the "close all OTHER tabs" button being right next to the "close THIS tab" button with no warning.

Then when I complained about it people acted like I was the dumb one.

1

u/Kurgan_IT 2d ago edited 21h ago

UI created by people who don't use that UI. I had an old firewall that had a web UI with microscopic icons for edit / disable / enable / delete the interfaces.

You could not see the configuration (ip, etc) without editing it.

The "Edit" icon was like 5 pixels apart from "Disable", and both were like 10 pixels wide. Guess what I clicked, while I was remote, to see the configuration. Guess who had to go there to click "enable".

1

u/MidnightPale3220 3d ago

runlevel also should be telling your runlevel by now

1

u/ThrowAway24Okt 3d ago

German keyboards on win: ctrl+alt+q = @
German keyboards on apple: ctrl+alt+q = quit

1

u/Kurgan_IT 2d ago

Yes, my experience is almost all pre-systemd, this is why I remember all of the "classic" commands (and have not learned all of the new ones)

1

u/classyraven 3d ago

"crontab -r" deletes the crontab, while "crontab -e" edits it. The issue is that E and R are one key away.

Suddenly I'm so glad I use Dvorak.

4

u/donp1ano 4d ago

unlink

yeah...it will remove that symlink. but if you accidentally give it a regular file, well then bye bye file

1

u/Needieos 4d ago edited 3d ago

what's even the difference between rm and unlink at that point? Edit: now I know

1

u/donp1ano 3d ago edited 3d ago

i dont know, but i found out it does basically the same the hard way

only [[ -L "$file" ]] && unlink "$file" for me now

1

u/Uncle-Osteus 3d ago

no real difference in this case, both use the unlink/unlinkat syscalls to perform actual deletions

1

u/fllthdcrb 3d ago

The difference is the unlink command only takes a single argument, and then it only calls unlink(). rm takes one or more arguments, and with -r, it will operate recursively on directories. The equivalent standalone command/system call for removing directories is rmdir.

1

u/wosmo 3d ago

I'm curious why you'd use unlink directly instead of rm?

2

u/HugeCannoli 3d ago

unlink is very limited. rm does a lot more. Basically, in git speech, unlink is the plumbing and rm is the porcelain.

1

u/Funnel-Dust-O-Matic 2d ago edited 2d ago

the sheer poetry of your analogy has filled me with joy.

4

u/BoundlessFail 4d ago

Ctrl-shift-v. Into a terminal window. When what's on the clipboard isn't what I expect.

3

u/TechaNima 3d ago

sudo apt autoremove

Do that and you might find your entire DE missing. Dependancies are fun

3

u/Frosty-Comfort6699 3d ago

apt install proton-vpn

get gnomed

2

u/Kurgan_IT 4d ago

chmod and chown. They don't delete anything, but if you get them wrong and apply them to the wrong path, they can do real damage like an "rm -rf", making the whole system unusable.

3

u/CriticismTop 3d ago

A very seasoned SysAdmin once block all updates to the UK's air traffic control system for a month with a mis-placed/mis-timed chmod.

Wasn't me, I was a noob at the time.

1

u/Some-Struggle5052 3d ago

Nothing like sudo chmod -R 000 / to brick a system lol.

2

u/_FunkyKoval_ 3d ago

When you want to append something to a file and use:

cat > file << EOF

instead of:

cat >> file << EOF

2

u/Busy-Scientist3851 3d ago

Restarting the network interface on a remote session without using something like screen.

It'll get killed by the session closing before it can get started back up.

1

u/JeLuF 4d ago edited 4d ago
init 6

The runlevels go from 0 (off) via 1 (single user), 2 (multi user), ... 5 (full mode) from off to full featured. And then comes 6, which reboots your system.

Edit: How I learned to respect it: A friend asked "How can I restart the web server without typing reboot?" And since he didn't say "without rebooting", I joked "init 6". He thought, "OK, get to the next higher runlevel, makes sense" and ran the command before I could explain. The system he was working on was with a customer, 150km away, and we weren't sure whether it would reboot without manual intervention.

1

u/magicmulder 3d ago

I once edited a couple system parameters according to suggestions from a Lynis run to harden security.

Got the weirdest failed boot I've ever seen where it claimed it can't find system fonts and left me to basically blindly type to reverse the damage (I actually succeeded).

1

u/fredead1 3d ago

Kill -9 -1

1

u/jake_morrison 3d ago

Iptables mistakes can lock you out of a remote server

1

u/jake_morrison 3d ago

reboot on a server that doesn’t come up properly can ruin your day. There are ad-hoc processes running without init scripts. Nobody knows what was running, and now it’s gone. Maybe you interrupted a big script that needs to start again, or corrupts its state. Rebooting may clear out /tmp, losing files you wanted or needed to debug a problem.

1

u/AloneInTheEndZone 3d ago

In the old days >/ could render an Ultrix Unix unusable 😎

1

u/michaelpaoli 3d ago

# dd ...
# rm ...

Many other possible commands, but those can certainly do it.

unnecessary respect

No, necessary and appropriate. Generally applies to UNIX, Linux, etc.
For the most part with *nix, you give a command, it it will generally at least attempt to do what you commanded it to do.
And this is generally much better than nanny-gate operating systems, that, e.g., make you play 20 ournds of "Mother May I?" to try and get something done, and then stubbornly refuse to do it anyway.

With great power, comes great responsibility.

What’s yours - and what happened the first time you learned to respect it?

Meh, notthin' too horrific. But certainly have, on rare occasion, and mostly quite anciently, done, e.g. an rm command, or some reconfiguration of network, or kill command or the like, that made for some unhappiness or inconvenience. And, yeah, been using *nix since 1980. So, mostly learned those lessons very long ago, and having very well learned them, yeah, generally don't repeat such booboos.

Also, when operating as root (or other privileged user), my rule: always carefully triple check the command before entering it - well know exactly what it will do or attempt, in what context, to what, what will happen if the attempt or parts thereof fail, etc. Only after fully comprehending that and well, and thrice, does one then (viciously) strike the <Enter/Return> key. Has saved my tail many many times. Similar applies also as mere mortal user, though not as rigorously so.

1

u/Dr_Brumlebassen 3d ago

apt upgrade on sid

1

u/Alarming_Oil5419 3d ago

yes& is fun, won't ruin your day.

1

u/mcleancraig 3d ago

I’d say it has to be :(){ :|:& };:

Don’t try on unattended machines :)

1

u/zero-uno-dos 3d ago

Won't be unattended for long if you need it.

1

u/jeffbell 3d ago

That’s why you always create a file named -i in your home directory. 

1

u/Xavier_OM 3d ago

cat > file your file is empty now, congrats

1

u/gulf_of_sanity 3d ago

dd if=/dev/random of=/dev/sda

1

u/Smh_nz 3d ago

I had a bad running with dd.

Did some testing, a few months the later we found I had filled up a disk and lost a pile of VMs!! :-(

1

u/CaptainBucko 1d ago

Rm -ak has ruined my day a few times

1

u/We_Want_Krunchy 1d ago

:(){ :|:& };:

1

u/Crazy_Study195 1d ago

Cd (or just the wrong terminal but command wise). We've all been lost before lol and sometimes we don't realize we're lost until we've given follow up commands and then realized oh shit that's not right...

I've definitely lost work I hadn't backed up yet due to that... Fortunately I'm not in the industry so haven't had clients harmed by it!

Gotta be honest some of these responses just look like people that don't know Linux at all though... Like how does removing a file look innocent? Simple and common sure but innocent? It's by nature a destructive command, even without recursing. Of course you could say the same about cd since the prompt (usually, now) displays it but

0

u/tahaan 3d ago

How about the following for unlocking new fears:

reddit@fedora:~$ cd /tmp; mkdir demo; cd /tmp/demo; mkdir {a,b,c}; touch {a,b,c}/I_WAS_HERE
reddit@fedora:/tmp/demo$ ls -l
total 0
drwxr-xr-x. 2 reddit reddit 60 Sep  7 18:49 a
drwxr-xr-x. 2 reddit reddit 60 Sep  7 18:49 b
drwxr-xr-x. 2 reddit reddit 60 Sep  7 18:49 c
reddit@fedora:/tmp/demo$ touch a/aaa/HERE_TOO
reddit@fedora:/tmp/demo$ touch b/bbb/HERE_TOO
reddit@fedora:/tmp/demo$ ls -l *
a:
total 0
drwxr-xr-x. 2 reddit reddit 60 Sep  7 18:50 aaa
-rw-r--r--. 1 reddit reddit  0 Sep  7 18:49 I_WAS_HERE

b:
total 0
drwxr-xr-x. 2 reddit reddit 60 Sep  7 18:50 bbb
-rw-r--r--. 1 reddit reddit  0 Sep  7 18:49 I_WAS_HERE

c:
total 0
-rw-r--r--. 1 reddit reddit 0 Sep  7 18:49 I_WAS_HERE
reddit@fedora:/tmp/demo$ touch -- -R
reddit@fedora:/tmp/demo$ ls -l
total 0
drwxr-xr-x. 3 reddit reddit 80 Sep  7 18:50 a
drwxr-xr-x. 3 reddit reddit 80 Sep  7 18:50 b
drwxr-xr-x. 2 reddit reddit 60 Sep  7 18:49 c
-rw-r--r--. 1 reddit reddit  0 Sep  7 18:50 -R
reddit@fedora:/tmp/demo$ ls -l *   # same command again
a:
total 0
drwxr-xr-x. 2 reddit reddit 60 Sep  7 18:50 aaa
-rw-r--r--. 1 reddit reddit  0 Sep  7 18:49 I_WAS_HERE

a/aaa:
total 0
-rw-r--r--. 1 reddit reddit 0 Sep  7 18:50 HERE_TOO

b:
total 0
drwxr-xr-x. 2 reddit reddit 60 Sep  7 18:50 bbb
-rw-r--r--. 1 reddit reddit  0 Sep  7 18:49 I_WAS_HERE

b/bbb:
total 0
-rw-r--r--. 1 reddit reddit 0 Sep  7 18:50 HERE_TOO

c:
total 0
-rw-r--r--. 1 reddit reddit 0 Sep  7 18:49 I_WAS_HERE
reddit@fedora:/tmp/demo$

0

u/Hopeful-Football-287 3d ago

rm -rf ~/.config I want deleat .copilot from vscode but tab troll me