The famous devil command rm -rf / in the engineer neighborhood
I often hear of failure stories that I've been doing with this command for a long time, but at last a familiar person has made it w
Therefore, we will consider measures to prevent recurrence.
At first
This article is about prevention measures. If you arrive at this article after doing something, this article may be helpful.
rm -rf /
Simply put, the command to delete everything.
If you write each one super easily, it looks like this.
rm | The delete command. rm [削除するファイル] |
-r | Option to delete directories as well as files |
-f | Option to recommend deletion without giving detailed messages |
/ | All |
See here for more information
trash-cli
I found somethi
ng called trash-cli. When introduced, the following command is added:
- trash-put – Go to Recycle Bin
- trash-list – list of recycle bins
- trash-restore – restore from recycle bin
- trash-empty – empty the recycle bin
- trash-rm – delete individual files from recycle bin
By linking the trash-put i
n this
with the rm command, deleted files and directories will once enter a dedicated recycle bin. (Can be restored from there arbitrarily)
Install
The environment is Mac. It seems to be available in other environments, but I haven't tried it.
As of October 23, 2020, it was v0
.17.1.
$ brew install trash-cli
Set the alias of rm to trash-put
Wh
en rm is called, set the alia
s to run trash-put instead.
The following .bash_aliase add
ed to the ~/.bash_aliase page. If you don't have a file, create a new one.
if type trash-put &> /dev/null
then
alias rm=trash-put
fi
Add the followi
ng to ~/.bashrc: If you don't have a file, create a new one.
if [ -f ~/.bash_aliases ]; then
source ~/.bash_aliases
fi
Apply ~/.bash
rc to make sure the aliasing is going well.
$ . ~/.bashrc
$ alias rm
alias rm='trash-put'
I'll test it.
Try deleting it and try restoring it.
# Make a suitable file
$ touch test.txt
# Delete it
$ rm test.txt
# Check the contents of the recycle bin
$ trash-list
2020-10-23 20:04:08 /Users/tabesala/Downloads/test.txt
# Restore (this time, I want to restore file No.0, so enter 0)
$ trash-restore
0 2020-10-23 20:04:08 /Users/tabesala/Downloads/test.txt
What file to restore[0..0] : 0
A problem or something to be aware of
Since it seems that file recovery is not university, it may be difficult
to restore when you really rm -rf / w