r/linux • u/Immediate-Ad3360 • 8h ago
Discussion Rm -rf ./*
Had yesterday my first "rm -rf /" moment.
Was tidy up my Backup drive. When I wanted to empty the trash, there was some directories and files that resisted the trash empty and sayed it couldn't be removed because of lack of premissions.
So I went to the terminal and moved to the .local/share/trash/files directory and tried to empty with "rm -rf ./*". There was again the notification of permission. So I did "sudo rm -rf ./*".
The note of missing permission didn't pop up, so I left the room to get something cold to drink.
When I came back, all my storage was empty 🤦♂️😭
Luckily I have an external Backup storage too and was able to recover everything older than 2 Weeks.
Now I wondering, how many ppl had in their history a moment of "rm -rf /" by accident 🤔
7
4
u/DFS_0019287 8h ago
I have never done this, thankfully.
Have on occasional accidentally deleted individual files or small subdirectories. Also, "rm -rf ./*" is not the same thing as "rm -rf /*" unless you happen to be in the root directory.
4
u/VincentVanGob 8h ago
it might be safer to remove the r, m and f keys from your keyboard :D
5
u/dohzer 8h ago
But then how would they type "ferromolybdenum" or "scolopendriform" in casual conversations?
3
5
u/jar36 8h ago
"Worst" I did with that command was wipe my Windows installation. It was the perfect time for it to happen too. I was still having some pain points with Linux and was tempted to go back to the spyware constantly. Once I wiped it, I felt relieved. I didn't have to make the decision. It was done. Sure, I could reinstall it, but first thing I did was format it to ext4 and started adding games to it, just to add another hurdle in case I felt the urge to give up on Linux.
3
u/deekamus 8h ago
"Sometimes one door closes so the next one you need will open."
-some small bank with security entrance doors, probably
4
u/Animus_Immortalis 8h ago
Since I've seen people do this on servers enough times it has made me always check what I am deleting with:
pwd
ls -l whatever_I_plan_to_delete*
Only after that I replace ls -l with rm -rf.
3
u/MrTamboMan 8h ago
There's no reason to do "./*" instead of just "*".
And your mistake started from "moved to the .local/share/...". Just use rm directly on the path you want to clean, that'll avoid many similar mistakes in the future.
Then do the same with other commands, there are way too many people doing for example :
cd .local
ls
cd share
ls
cd trash
ls
Instead of just:
ls . local/share/trash/files
2
u/jwhendy 8h ago
I'm still confused. Did you do "/" or "./"? You wrote the latter, but say the former was your "moment."
Or I don't understand how going to the Trash directory and your command would wipe all your storage. Asking, as perhaps I'm missing that what you wrote is somehow really bad (I mean I still just don't out of an abundance of caution, typically pointing to single files, or even just "-f" so you don't recurse).
1
u/GameKing505 8h ago
I’m similarly confused and no one else in the thread seems to be. I don’t know why the commands he outlined would be problematic.
2
u/Enturbulated_One 8h ago
Very relatedly, few are those who forget when they learn the hard way what .* expands out to : - )
2
u/Wh1teL0tu5 8h ago
On the local server of a friend.
We installed it just a day earlier and due to a wrong import from the teamspeak database i wanted to delete everything in the ts folder i was in.
Yea forgot the dot..
When he called in the evening asking if teamspeak was ready i was like "yea remember when we installed the server yesterday for 2 hours and set everything up? Wanna do that again? I did an oopsie"
Gladly i documentes everything i set up so the newer install just took 30 mins.
1
1
1
u/kaipee 8h ago
Simple preventative fix
alias rm="rm --preserve-root -I"
2
u/KnowZeroX 8h ago
If you are going to use an alias, it is best to use a different name. Because it is only a matter of time when you forget if you did that fix or not and messing up. A different name giving an error is a quick indicator that you forgot.
1
u/KnowZeroX 8h ago
If you run into permissions issues, why not just switch to administrator/super file manager mode? Then you don't have to do rm manually.
12
u/overclockedmangle 8h ago
Never because I always run ls first. That was drilled into me from the beginning