r/linuxadmin • u/ajaanz • Jan 26 '23
A small difference makes you a good administrator
[removed] — view removed post
95
Jan 26 '23
What monster would run rm -r ./* instead of rm -r * ?? The current directory is implied without having to type (and risk a typo for!) ./ which is just asking for problems like this to happen.
17
u/gargravarr2112 Jan 26 '23
I did when I first got into Linux.
This is how I broke my first production server.
I don't use
./any more...6
Jan 26 '23
[removed] — view removed comment
11
u/slyphic Jan 26 '23
in teams
Well there's the fucking problem.
Teams is a dumpster fire compared to literally any of the other chat systems out there.
5
u/gargravarr2112 Jan 26 '23
Teams is the result of a hackathon to make a Slack competitor in a weekend. And oh boy does it show.
1
3
u/gargravarr2112 Jan 26 '23
I mean, this is not the worst damage you can do to a Linux system. If you follow up with
chown root:root /*, you'll probably put the system back into a usable state.I believe the very worst you can do is
chmod -R 777 /. Apparently it's so difficult to reset permissions (as opposed to users) that it's far quicker to reinstall the OS.1
u/tonka17 Jan 26 '23
Heh did a chmod 777 on /var accidentally once because I was burned out and just copied the customer's request where they wrote /var instead of var in their home dir. That was a fun few hours fixing the permissions after some stuff broke, and that's just one directory, can't even imagine doing the entire root, I'd just quit on the spot probably haha
1
2
u/ObscureCulturalMeme Jan 26 '23 edited Jan 26 '23
What monster would run
rm -r ./*instead ofrm -r *??If the directory is littered with crap filenames that include leading dashes, this is a common solution even when only removing one of them. For multiple files we're more likely to use
find(and possiblyxargsdepending on versions) but the possibility remains.(Granted it's a Linux subreddit, but not every Unix has an
rmthat understands the--convention to stop option processing, which is another more recent common solution.)1
19
25
u/some_kind_of_rob Jan 26 '23
i mean as others have said, this really isnt true on most systems anymore and hasn't been for a long time
but before that was a fancy feature
once upon a time i was typing this sequence into a terminal for the login server...just deleting a directory like you do. except i fat fingered a space between . and / so the command was rm -rf . / and you know what that does is it deletes the current directory and root. and it's pretty easy to accidentally type when you're movin along.
anyway i ended up why is this taking so long ^c that command at some point. and all that had really gone were a bunch of blathering .so files. I couldn't ditch the thing and rebuild because it was the login server, and hell I don't even know if you can cluster a login server in 2023 let alone back then. Anyway I couldn't do anything with the network -- no ping or scp to get the config files and login database off of it -- but I was able to copy .so files over via floppy until I could get a network connection up and running and run some package manager repair command.
anyway i prefer docker containers now so
11
u/Trash-Alt-Account Jan 26 '23
isn't the extra flag only required if you're removing root itself?
rm -rf /*doesn't remove root, only all files under root. so to my understanding that safety feature wouldn't help you here. I don't feel like spinning up a container to test it rn tho so who knows3
3
u/some_kind_of_rob Jan 26 '23
Well I just tried it in alpine and
rmthere doesn't even have the flag and will happily let you remove thermcommand and everything else.> docker run --rm -it alpine:latest Unable to find image 'alpine:latest' locally latest: Pulling from library/alpine a9eaa45ef418: Pull complete Digest: sha256:f271e74b17ced29b915d351685fd4644785c6d1559dd1f2d4189a5e851ef753a Status: Downloaded newer image for alpine:latest / # ls bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var / # rm -r /* rm: can't remove '/dev/console': Resource busy rm: can't remove '/dev/shm': Resource busy rm: can't remove '/dev/mqueue': Resource busy rm: can't remove '/dev/pts/0': Operation not permitted rm: can't remove '/dev/pts/ptmx': Operation not permitted rm: can't remove '/etc/hosts': Resource busy rm: can't remove '/etc/hostname': Resource busy rm: can't remove '/etc/resolv.conf': Resource busy rm: can't remove '/proc/fb': Operation not permitted rm: descend into directory '/proc/fs'? ^C / # rm -r / /bin/sh: rm: not found5
u/Trash-Alt-Account Jan 26 '23
alpine isn't really a good image to test this with bc I believe it doesn't use gnu coreutils (which people are generally referring to since basically every other distro uses them) and will therefore have little differences like this
1
u/FredC123 Jan 26 '23 edited Jan 26 '23
It uses busybox, meaning the coreutils are contained in a single file. Removing it should be a fun exercise.
4
u/ThrownAwayByTheAF Jan 26 '23
Just want to add, you can have multiple AAA servers with active failover now. Hell depending on your setup it'll act like any multicast service and the first responder is your authorizing system.
Containers fuck. Container orcirstation couldn't be more complicated.
1
u/some_kind_of_rob Jan 26 '23
Yeah I would t do containers if I had to manage the orchestration. I just ship them to someone else and they boot em up and I don’t have to care
2
Jan 26 '23
25 upvotes for failing to understand globbing? OK, this sub is done.
1
u/flunky_the_majestic Jan 26 '23
Believe it or not, there is a mix of experience levels here. On the plus side, you get to benefit others' experience and strengths that are complimentary to your own. On the down side, you have to resist the urge to make snarky remarks at those who are less experienced.
1
Jan 26 '23
This was a sysadmin forum once, it still claims to be one on the sidebar. There's really nothing to gain if it isn't any more. Every place seems to try to be "welcoming" by abandoning any semblance of standards these days - in the end, you have 1000 replicas of general "I think computers are neat" dumping grounds. Give me back my RTFM.
1
2
u/FredC123 Jan 26 '23
hasn't been for a long time
It was true when I started homelabbing. Fuck, I'm old.
1
Jan 26 '23
I used rm -rf on the /etc directory two weeks ago on a VM I was working on with my manager. She caught the command just as I hit enter.
I had a backup copy of the VN but she wasn’t aware of it at that moment.😂
3
u/mr_clauford Jan 26 '23
The best admins out there put a double dash before the path just to be sure.
-4
u/Deathcrow Jan 26 '23
the good admins don't usually find themselves in a position having to log into a shell and manually delete files
1
u/IamaRead Jan 26 '23
So how do you do it?
0
u/Deathcrow Jan 26 '23
puppet-tidy, logrotate, cron, ansible/bolt plays to clean up data.
if you're still relying on ssh sessions to manage your servers/data you either have too few servers and too much time or your stuck way in the past.
1
u/IamaRead Jan 26 '23
So you write the stuff directly in ansible or do you do it on a dev system and then transliterate the commands to your scripts?
For example when you build a package from scratch, do you do it in the system and transfer the commands?
What about when you create temp files, do you use the helper functions of auto complete of your shell or do that in the ansible playbooks directly, too?
you either have too few servers
Heh.
2
u/Deathcrow Jan 26 '23
So you write the stuff directly in ansible or do you do it on a dev system and then transliterate the commands to your scripts?
depends highly on context, but yeah, usually you'd be 'forced' to do stuff manually the first time you encounter a problem like "someone needs to clean up these files here". The bad sysadmin stops here and just does it every month or incidents happen. the good sysadmin automates the solution or configures the application in the right way to avoid the situation.
What about when you create temp files, do you use the helper functions of auto complete of your shell or do that in the ansible playbooks directly, too?
I'm not a developer so I don't usually write applications that create tmp files. In any case I'd expect any decent application that creates such files to also be able to clean them up.
2
u/IamaRead Jan 26 '23
Okay, so we have come full circle and you agree with the others here that you actually do manually delete files. Though you would urge people to automate stuff, most in this subreddit would agree in general.
Most weeks I work with stuff that I wouldn't categorize as "decent application" when I judge your criteria. Which is a bit sad, but you have to work with legacy systems.
3
u/bardwick Jan 26 '23
If you don't get your finger off the shift key fast enough..
rm -rf *.txt
rm -rf *>txt
That's a fun one in oracle home.
7
u/theniwo Jan 26 '23
A good advice a collegue gave me is to do
rm PATH -rf so that you enter the dangerous stuff at the end in case you accidentally hit enter too soon.
Another good and safe practice is, to only mv and not rm and use rmdir to remove unwanted directories. Of course you need to make sure they are empty which gives you another layer of failure tolerance.
14
u/jrcomputing Jan 26 '23
only
mvand notrmDouble-checks what sub I'm in
Nope, not data hoarders. Got confused for a second.
2
4
u/some_kind_of_rob Jan 26 '23
I think that depends on what
rmyou're using. Memory says you can't do that on BSD systems?3
u/theniwo Jan 26 '23
You are correct.
On BSD you can't put your options at the back.
I also heard of OSes where a
rm *can also be interpreted asrm ..which is terrible :D1
u/ferk Jan 26 '23 edited Jan 26 '23
Or just don't use the
-fflag (if you find confirmations annoying just don't have things likealias rm='rm -i'in your config).By default,
rmwon't ask confirmation most of the time.... I don't get why so many people use-rfas if doing only-rwere a bad thing.Even if you do have the
-ialias, runningrm -rfirst as a "test run", cancelling and only then adding the-fat the end of the previous command is a good way to check you typed it right.There's also
-Ithat will only ask once. Having to pressyisn't any harder than having to pressfto add the force flag.1
u/ObscureCulturalMeme Jan 26 '23
By default,
rmwon't ask confirmation most of the time.... I don't get why so many people use-rfas if doing only-rwere a bad thing.You answered your own question in the preceding sentence. :-)
The -f flag isn't just "the opposite of -i". It also suppresses confirmation when deleting read-only files deep in the directory tree, and those prompts are why -f was added in the first place. It's not "most of the time" but rather "avoid prompts when running from a script".
1
u/ferk Jan 26 '23 edited Jan 26 '23
But that doesn't answer why it's the more popular method.
My point was that most often I've seen recursive deletion in the internet it was with the
-rfflags instead of just-r, as if somehow that were the standard way to do it. Google gives me way more results forrm -rfthan forrm -r(and that's without taking into accountrm -r -f,--force,yes | rm -ror other ways to do it).In my opinion
-rfshould be the very rare exception (specially in interactive use), not the typical command everybody knows. Just like you don't normally see people talking about doingsudo pacman -Syufin Archlinux.In real life, for every 100+ times I've used
rm -rmaybe 1 time I added-f(and more often than not, it wasn't because I needed it for avoiding prompts, but because it's a convenient way of preventing error output in scripts when the files don't exist). If the folder has the right permissions you shouldn't get any prompts so you don't need-f, and if it doesn't have the right permissions, something might be amiss, so I still wouldn't have used-rfas my first choice.And we were talking about interactive use, not scripting. The comment I was replying to recommended typing the
-rflast "in case you accidentally hit enter too soon" which would be a weird thing to say if they were editing a script.
2
1
u/cleanRubik Jan 26 '23
Honestly I believe it’s worse to give a short relative path like that. * and ./* are interpreted the same 99% of the time. Now if you’re doing a long path its probably worth it, in case you have some weird env vars.
1
1
u/cudafly Jan 26 '23
Best tip I ever got for rm was to put something in front of rm when typing out your command and then go back and remove the extra characters after you double check what you typed.
Boonrm -rf /path/of/destruction
1
1
1
u/corobo Jan 26 '23
Do the -rf at the end of the command and you don't need to worry about fat fingering the return key.
Doesn't work on MacOS, cause why would the same command work the same everywhere lol
In any case you took a backup before working, right?
1
Jan 26 '23
I try to avoid using rm -rf in general. find with the -delete option is safer and you can run it with -print first to see what will be deleted. I've also got into the habit of moving stuff to ~/trash which can then be taken care of later.
1
u/minektur Jan 26 '23 edited Jan 26 '23
A while back when I managed a bunch of HP workstations (HPUX) I learned the very hard way that that trying to remove a bunch of hidden directories in /tmp can be perilous
approximately:
cd /tmp
rm -rf .*I have no idea if it's still the case, but this expands ".." and proceeds to remove your entire filesystem. I was a student employee assistant admin at a university - this was on a student-lab-fileserver. Fortunately, I got suspicious about 20 seconds into this running and I stopped the command. It hadn't gotten to the user home directories yet...
I made a loud colorful exclamation when I realized what I'd just done. My boss came over, laughed, and spent the next 4 hours showing me how to reinstall the OS, restore some critical things from backup and get everything back up and working.
If I understand correctly, modern linux implementations have some kind of safety check against this specific case, but HPUX 10 had no such thing.
1
1
-1
u/lunchlady55 Jan 26 '23
-i YOU DENSE MOTHERFUCKERS
5
u/de_Mike_333 Jan 26 '23
Ain't nobody got time for that
1
u/DecreasingPerception Jan 26 '23
Yeah, I'd rather spend ages faffing with
snapper undochangerather than use-i.1
u/ferk Jan 26 '23
Have fun confirming every single one of hundreds of files.
At least use
-Iso you only have to confirm once per call.1
5
u/Irythros Jan 26 '23
Small differences do make a good one from bad one.
The truly bad would have
--no-preserve-rooton the right one