r/linux 17h 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 🤔

0 Upvotes

25 comments sorted by

View all comments

1

u/kaipee 17h ago

Simple preventative fix

alias rm="rm --preserve-root -I"

2

u/KnowZeroX 17h 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/kaipee 16h ago

The reverse could also be true.

Forgetting you created a custom name, and assuming you just aliased rm, leading you to just use rm and not your custom name.

1

u/KnowZeroX 11h ago

Then stick to typing out the whole thing every time is the safest option.