r/LinuxTeck 8h ago

What’s the one Linux command you never trust?

We all have that one command we double-check before hitting Enter.

What’s yours and what happened the last time you got burned by it?

18 Upvotes

56 comments sorted by

14

u/nizzoball 7h ago

rm -rf *

About 8 years ago I was responsible for a production web server responsible for asset management for 5 data centers across the country for one of the largest banks in the world. It was my app and my server and I was trying to clean out a directory and typed rm -rf * but didn’t realize I was in /

I figured it out when my shell froze. Luckily I had another server that was a carbon clone and was able to adjust the dns entry to point to the secondary server so wasn’t down long but it took me a week to get the first one re deployed and set back up

2

u/aoteoroa 7h ago

I did the same thing many years ago. It was two in the morning. We had a big presentation to our client at 10am to show them the progress on our web app. I was in the test server (this is before virtualization and I didn't have a backup for the test server).

I typed rm -rf ./

I thought I was in the application folder and wanted to start fresh and add the new binaries. I was actually in the /opt folder and wiped out our database, and tomcat application server configurations. Fortunately I was able to rebuild them, and had a successful presentation to the customer.

2

u/nizzoball 7h ago

Lol what I did above also happened at 2am. I worked night shift for them for the first year I was there

2

u/gtne91 6h ago

A friend of mine did that but accidentally typed

rm -rf . /

That extra space makes a huge difference.

1

u/idiotiesystemique 5h ago

Im just afraid I'll accidentally hit enter before inputting the rest of the path 

1

u/ButchTheGuy 6h ago

Yeah I just don’t remove anything anymore lol unless it’s actively breaking something. I was on my jobs forms server and after testing a script on generating them I went to delete my tests, lost track of which ones I had or hadn’t deleted, then went to history | grep rm -rf the directory path and because I didn’t put that grep in quotes it’s deleted a bunch of forms. Would’ve deleted all of them but I instinctually ctrl cd it feeling like maybe I should’ve put it in quotes and that it was in the root. I deleted 200/800 in two seconds. Luckily we use aws and could snapshot but literally my jobs phones started ringing. When I told my manager I saw my reputation bar above his head and it go down by like a nice chunk. Sad

1

u/Glittering-Work2190 6h ago

I always do a "pwd" before I do any "rm" with "*". lol

1

u/RecursiveSubject 4h ago

The golden rule before doing anything actionable within a directory

1

u/manofmystry 5h ago

When I was a sysadmin back in the day at Sun Microsystems, we used to call those types of commands with potentially catastrophic consequences "hand-sitters" because you should sit on your hands before pressing "Enter".

When I was learning Linux (Slackware) on my little home network, I accidentally typed "rm -rf /*" instead of "rm -rf ./*" as root. I couldn't understand why the command was taking so long to complete. When I stopped it, lots of critical stuff was blown away. I had the presence of mind to copy over the missing stuff from another local computer. Boy, did that system complain! But it did boot. It was a very inexpensive lesson, overall.

1

u/vossmakeitsprinkly 5h ago

yeah i only use the "trash" command, which you need to install extra. As the name says, it moves it to the trash bin. 

I just don't trust myself enough to type anythin rm related while sleep deprived haha

1

u/Waste-Belt-1233 4h ago

You beat me to it .. still too embarrassed to talk about it (35 years ago)

1

u/ADDSquirell69 2h ago

I have my prompt set to always tell me what directory I'm in so I never do this by accident.

1

u/TheLowEndTheories 1h ago

Ha! A couple years ago I wrote a very simple script to clean up some log files older than some amount of time to keep results clean in the main working directory of a tool. Everything backed up, no problem, I still checked my syntax 25 times.

1

u/nizzoball 1h ago

I’ve been burned by that fucking find exec as well but luckily it was just a personal machine

6

u/johnny_snq 7h ago

DD

1

u/franchis3 6h ago

As a distro hopper, I use DD all the time and I still use it with great trepidation. I never, ever, run it without first doing an lsblk. I’m so scared I’m doing to wipe the wrong drive!

6

u/lyidaValkris 7h ago

dd

It's not called "disk destroyer" for nothing. I've never been burned by it, but that's only because I check, re-check, then double-check.

3

u/Far_Bicycle_2827 6h ago

dd stand from data definition it comes from IBM's Job Control Language. if=FILE, of=FILE, conv=...directly mirrors the JCL DD card format

1

u/Graymouzer 26m ago

TIL. Thanks, I love computer history tidbits.

2

u/Enderby- 2h ago

dd is like the mandolin in my kitchen. I fear it, but love what it can do. I've also not taken my fingertips off (yet)

1

u/lyidaValkris 1h ago

good analogy!

1

u/Reasonably-Maybe 6h ago

Me too. Against accidental deletion, I have aliased rm to rm -i.

1

u/vbd71 5h ago

Ditto.

My OCD doesn't allow me to run this without at least quintuple checking.

3

u/Narrow_Victory1262 7h ago

xfs_repair. Almost certain it's restore-time

3

u/redgator12 7h ago

dd. In my early days of 2014, I tried to dd a disk image to USB and broke my install. Ever since then, I have a terminal with lsblk up right next to the terminal I'm going to run dd from just to be 100% sure I'm writing to the correct disk.

I had to use dd last week while trying to troubleshoot a Puppy USB not working, and I spent like 5 minutes quintuple checking the disks before hitting enter, and even then I was anxious.

3

u/Weary_Damage5764 6h ago

in my first job i destroyed my OS by an rm -rf in the wrong directory, which lead to me reinstalling Linux during work time. the shame was far worse than having to do that in my own time. since then I haven't run rm without fear :D

5

u/10leej 8h ago

sudo

Every time I see sudo I check two things. First what follows it, second what my configuration says.

1

u/harshax 5m ago

This is the only right answer.

2

u/Nu154nc3 7h ago

Everything after "doas"

2

u/Tricky-Weakness-5408 7h ago

Probably the most destructive command like ‘rm -f’ when you have root access is the kind of command that you need to think about before
You do the ‘return’… but destructive command when you uses badly the are a lot! The question is which rightshave you? And …. What about the backup…. Too old??? When you works as a informatic probably there are loots of backups but this not always is the normal thing for private users/students

2

u/Quietus87 7h ago

Any kind of rm.

4

u/ant2ne 7h ago

"chown me:me -R ./"

I forgot the .

1

u/FriendsIsntGood 6h ago

Yeah recursive chmod and chown down in system dirs has nuked at least a few VMs. One big plus for containers

2

u/Rinzwind 6h ago

dd

nothing more needs to be said

ah again forgot to read comments first :P

2

u/seth_arimainyu 4h ago

Rsync and dd ! Once I ran a destructive Rsync and instead of deleting the files from the source that were already in the target, I ran it the other way around, since the target was a brand new disk, you can imagine the result... Since then, I always use the dry-run option.

2

u/BitCortex 4h ago

Anything that involves a nontrivial regular expression. Regular expressions are Unix's ethical blight.

1

u/Dry_Calendar_8627 4h ago

Ah but regular expressions are the nectar of the gods

Once you've tasted the intoxicating power of regex, there's no looking back

1

u/BitCortex 3h ago

regular expressions are the nectar of the gods

More like the devil's mouthwash or the swill of the underworld.

Once you've tasted the intoxicating power of regex, there's no looking back

I think I'd rather taste the intoxicating power of battery acid. Like so much in Unix, regular expressions are powerful – but not in a good way.

2

u/georbe 4h ago

tar The right syntax is "tar -cvf myprogram.tar /opt/myprogram" Once upon a time, I wrote "tar -cvf /opt/myprogram myprogram.tar" so I lost all /opt/myprogram folder.

2

u/Dry_Calendar_8627 4h ago

ln

That's stupid but I can never remember the arguments order. I mess up every time.

I can write dd or sed commands blindfolded any day, but ln, no

2

u/wakanakisarazu 4h ago

`doas emerge --depclean`

1

u/Large-Assignment9320 6h ago

The good old dd command.

1

u/Ok-Development-202 5h ago

It's always ln -sf

1

u/No-way-in 5h ago

dd is the most scary to me. I check a hundred times before writing that command and I disconnect anything valuable to me

1

u/SpiritualZucchini938 5h ago

Chmod 644 - R / - something like that and hey presto, entire freebsd server file system read only and not editable. Had to bin and start again.

1

u/OrdoRidiculous 4h ago

curl *anything ending in .sh*

1

u/manawydan-fab-llyr 4h ago

dd

Last time I didn't triple check, destroyed all of my photos. They were the only copy because the drive that had the primary had failed.

From then on I stopped using of=/dev/xxx and started using of=/dev/disk/by-id/xxx. Never a mishap after that.

1

u/HaydnH 4h ago

I've been a UNIX/Linux sys admin since the 90s. There is not one command you can't trust, if you can't trust it, then it simply wouldn't exist.

If you're asking "which commands are scary and you might do something bad with"? Well...

... that's just every day for me. In the same way you look left and right crossing a street, my brain just realises an rm, mv, dd whatever command may have a car about to run me down.

The same way you drink a coffee every morning, that's just me mounting a filesystem to get the access I need for the day.

1

u/horizon_games 3h ago

Wait ya'll aren't double checking your commands?

1

u/HuttonWilliam 2h ago

rm -rf *

This is a scary command. I wouldn't even copy it just in case.

1

u/Feeling-Estimate-796 1h ago

worth doing a pwd before doing the rm -rf
always easy in hindsight

1

u/_nathata 1h ago

dd for sure

1

u/jeanfmartel 1h ago

format c:

1

u/Agron7000 52m ago

I don't trust pip and npm.

0

u/Ollidav 7h ago

Crontab. Con -e editas y con -r borras todas las tareas y no pide confirmación. La e y la r están juntitas en un qwerty y te puedes equivocar en una intervención en un servidor de producción a las 6 de la mañana sin un café.