2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

あのコマンドを発動させてみた(rm -rf /)

Posted at

概要

エンジニアになれば一度は聞いたことあるであろう全てを消去するコマンド "rm -rf /"。
実際にやったことがなかったので試してみることにした。(←暇なの?)
もちろん仮想環境で試します(Dockerコンテナ)

実行環境

CentOS Linux release 7.5.1804 (Core)

実行!

仮想環境を起動し、おもむろにこのコマンドを入力する。

bash-4.2# rm -rf /

さあ、本当に消えるのだろうか。
実行!

bash-4.2# rm -rf /
rm: it is dangerous to operate recursively on '/'
rm: use --no-preserve-root to override this failsafe

・・・消えない
しかし、このオプション "--no-preserve-root" をつければいけそう。
改めて実行!

bash-4.2# rm -rf / --no-preserve-root

これで消えました。が、全てを消すことはできず、read-onlyになっているファイルは消せないと警告がでました。
本当に消えたのか ls コマンドを実行してみようとするが、コマンドがないため見れず。
というか、ありとあらゆるコマンドが使えなくなった。そりゃ全部消したんだからそうですよね。

生き残ったコマンドたち

!          bg         command    dirs       enable     fc         help       local      read       shopt      trap       unset
./         bind       compgen    disown     esac       fg         history    logout     readarray  source     true       until
:          break      complete   do         eval       fi         if         mapfile    readonly   suspend    type       wait
[          builtin    compopt    done       exec       for        in         popd       return     test       typeset    while
[[         caller     continue   echo       exit       function   jobs       printf     select     then       ulimit     {
]]         case       coproc     elif       export     getopts    kill       pushd      set        time       umask      }
alias      cd         declare    else       false      hash       let        pwd        shift      times      unalias

生き残ったファイルたち(配下の全てが無事というわけではなく一部だけ残っている)

dev/  etc/  proc/ sys/

以上!
"rm -rf / --no-preserve-root"はほぼ全てを消せるコマンドのようですね。
私の知識ではここからどうやって復活させるのかわかりません。
こうなったらもう最初からインストールした方が早いので、やる必要もありませんが。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?