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.
![](https://qiita-user-contents.imgix.net/https%3A%2F%2Fcdn.qiita.com%2Fassets%2Fpublic%2Farticle-ogp-background-412672c5f0600ab9a64263b751f1bc81.png?ixlib=rb-4.0.0&w=1200&mark64=aHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTk3MiZoPTM3OCZ0eHQ9JUU1JUE0JUE3JUU0JUJBJThCJUUzJTgxJUFBJUUzJTgzJTk1JUUzJTgyJUExJUUzJTgyJUE0JUUzJTgzJUFCJUUzJTgyJTkyJUU2JUI2JTg4JUUzJTgxJTk3JUUzJTgxJUE2JUUzJTgxJTk3JUUzJTgxJUJFJUUzJTgxJUEzJUUzJTgxJTlGJUUzJTgxJTkxJUUzJTgxJUE5ZXh0dW5kZWxldGUlRTMlODIlOTIlRTQlQkQlQkYlRTMlODElQTMlRTMlODElQTYlRTUlOEQlQjElRTMlODElQUElRTMlODElODQlRTMlODElQTglRTMlODElOTMlRTMlODIlOEQlRTMlODElQTclRTUlOEElQTklRTMlODElOEIlRTMlODElQTMlRTMlODElOUYlRTglQTklQjEmdHh0LWFsaWduPWxlZnQlMkN0b3AmdHh0LWNvbG9yPSUyMzIxMjEyMSZ0eHQtZm9udD1IaXJhZ2lubyUyMFNhbnMlMjBXNiZ0eHQtc2l6ZT01NiZzPTE1MTMxOWMyZWQxYzEyZTk4N2I3N2YyNWJjNjJjZDQw&mark-x=142&mark-y=57&blend64=aHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZoPTc2Jnc9NzcwJnR4dD0lNDBkb2xjYW5vJnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9MzYmdHh0LWFsaWduPWxlZnQlMkN0b3Amcz01ZmE4ZDQ5MDUwMThhYjMxN2IyMjkzYjJiZDk4MjM4Yg&blend-x=142&blend-y=486&blend-mode=normal&s=fc26d7b47be961c9ae59f633f987875c)
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
![](https://image.itmedia.co.jp/ait/files/20010101/backn2.gif)
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