How far you can get, it's basically depend on the specific Unix/Linux distributions.
But to answer your base question, yes -
rm command would be removed with it as well as any other standard command in
/bin and other folders.
Here is the simple test which I've performed in Linux Ubuntu 15.04 using VM.
Initialize virtual machine via
vagrant init ubuntu/vivid64 && vagrant up --provider virtualbox && vagrant ssh
Then when you're trying to remove all the files in the standard way, it doesn't let you:
vagrant@vagrant-ubuntu-vivid-64:~$ sudo rm -fr /
rm: it is dangerous to operate recursively on '/'
rm: use --no-preserve-root to override this failsafe
So lets try
--no-preserve-root. Always double check you're logged in virtual machine (so you're having
vagrant@vagrant-ubuntu-vivid-64:~$), then run (don't try that at home):
vagrant@vagrant-ubuntu-vivid-64:~$ sudo rm -vfr --no-preserve-root /
removed directory: '/lost+found'
removed directory: '/opt'
removed directory: '/bin'
removed directory: '/usr/games'
removed directory: '/usr/bin'
removed directory: '/usr/lib/gcc/x86_64-linux-gnu/5'
removed directory: '/run/initramfs'
removed directory: '/media'
rm: cannot remove '/proc/fb': Operation not permitted
rm: cannot remove '/proc/fs/ext4/sda1/options': Operation not permitted
removed directory: '/boot'
rm: cannot remove '/dev/hugepages': Device or resource busy
rm: cannot remove '/dev/mqueue': Device or resource busy
rm: cannot remove '/dev/shm': Device or resource busy
rm: cannot remove '/sys/fs/ecryptfs/version': Operation not permitted
removed directory: '/etc'
removed directory: '/mnt'
removed directory: '/vagrant/.vagrant/machines/default/virtualbox'
removed directory: '/vagrant/.vagrant/machines/default'
removed directory: '/vagrant/.vagrant/machines'
removed directory: '/vagrant/.vagrant'
rm: cannot remove '/vagrant': Device or resource busy
After that it gets back to the shell prompt like nothing just happened, but you can't execute any commands anymore apart of few built in and
kill, so you can finish your job and kill your session:)
rm: command not found
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
$ which kill
-bash: /usr/bin/which: No such file or directory
$ kill -9 $$
Connection to 127.0.0.1 closed.
So it pretty removed everything, including
ls and all other commands, but still you're logged-in. There are some special folders which weren't removed such as some devices from
/sys which are aren't regular directories/files, but it's pseudo-filesystem providing interfaces to process and kernel data.
If you're interested in possibilities of recovering from such disaster, check: