Here’s the thing

You’ve all heard the joke: a programmer goes into an interview and is told to write a shell script

The programmer ended up writing a simple RM -rf /* on the company machine

Today bloggers are bored with curiosity to see what the effect will be.

I took an unused virtual machine system and played with it.

Here to report the results:

Be careful: after playing, most of the data cannot be recovered and the system will basically crash completely,

It is recommended to play on an abandoned machine, not in a formal environment, and be careful when writing delete commands

Preparing for Linux Machines

First, find a VM that has not been used for a long time, return to the root directory, and run rm -rf *.

Then you start to see the system start deleting from the root directory

Started reporting errors that could not be deleted

Because some running misC NET and other hardware files cannot be deleted

Rm: cannot remove… If you stop, you can still be saved

Correlation path interpretation

Boot: indicates the boot path. Some files are running and cannot be deleted.

Misc NET: cannot be deleted because it is hardware related.

/ dev/SHM:

/dev: The directory contains some device hardware files, such as disks, memory, cameras, and network adapters. /dev/shm: this directory is Linux’s next memory virtual directory, the files in this directory are stored in memory, not on disk.

Its size is not fixed, that is, it is not stored in pre-allocated memory. (shm == shared memory)

dev/pts/ptmx

File systems related to PTMX virtual terminals cannot be deleted

Linux terminal:

Also, some system files in the sys directory include,

Root does not have permission to delete mounted disk information.

The other folders opt MNT home root and so on were deleted

Linux struggled: sys/ Block block devices would not be removed,

The cache, mount records, and locks of NFS file systems cannot be deleted

= = = = = = = = = = = = = =

Rm -rf /* After run

Once the deletion is complete, let’s look in the root directory:

The ls command is no longer available because all binary command files in the /bin directory where the command was stored have been deleted.

Yum PWD is gone, CD is still there,

This is because the CD command is not under /bin

Whereis CD: Check it out. The CD is in the /usr/bin directory

You can see that the only boot folder left in the root directory is /boot.

Hardware related MISC NET DEV

Sys system related folder

This is given to us next time we start up by starting the traction, after the traction to the GRUB interface

We deleted everything from the system, so it was stuck in the GRUB interface, unable to access the kernel.

Rescue and preventive measures

This command is extremely dangerous, so if misoperated

1. Abort command

First, as soon as you realize the command is executing, press Ctrl+C to terminate the command. Protect system files as much as possible.

2. Do not exit the current shell or restart it

Because we don’t know exactly what files were deleted.

There’s always a subconscious feeling that we just need to reboot. Do not restart at this time, because a restart, you may not be able to access the system, even the last chance to rescue.

3. System folder migration

The root directory of the system is basically these folders.

For example, /bin/sbin is a folder where commands are stored. If it is deleted, we can replace it by zipping /bin from another server to the current server and unzipping it.

4. System snapshot

This is a very practical approach. You can take a system snapshot periodically. For example, you can take a system snapshot at 2 am every day. You can also take a snapshot after major system updates or service builds.

This way, if we misoperate, we have a backup that falls back.

5. Command rewrite

Rm -RF can be rewritten to create a recycle bin.

“Your RM-RF /*, I took over the disk” — I sent her a command line version of “Recycle Bin” because my newly graduated operation sister always deleted files by mistake.