-4

I ran this command on Fedora, which I anyway wanted to uninstall, so I decided to check out this command: sudo rm -rf /* just for fun. As soon as I ran this command, the GUI stopped working and patches of black started appearing, I thought the work was done, and did a forced shutdown. [By the way, I was multibooting Windows 10, Linux Mint, Garuda Linux & Fedora]

When I rebooted, I was expecting Garuda Linux's Grub to show up, but nothing happened and DELL's Support Assist showed up. Then I learned from the BIOS, that the EFI partition was completely erased, which makes sense as it was the /boot/efi directory in Fedora. Then I had to go through the all the recovery stuff to get my OSs booting again.

I was worried that, like the EFI partition, which was mounted to Fedora was completely erased, all my Data partitions would also be erased with the command. But when I checked out after getting every thing right, every thing was saved. And even the Fedora partition had some space used.

I then formatted the Fedora partition from g-parted of Garuda Linux.

Now I wonder what exactly does the command: sudo rm -rf /* really does, just to check I didn't lose any other data.

4

1 Answer 1

5

sudo rm -rf /* (-r means to remove directories and their contents recursively and -f to ignore nonexistent files and arguments and never prompt for confirmation and /* just expands to everything in /) removes everything in / and as you found out with /boot/efi this also includes mounted filesystems. The reasons why some data was not removed can be:

  1. Partitions from your other distributions/operating systems were not mounted, rm can't remove data from unmounted devices/filesystems.
  2. They were mounted as read only.
  3. As Kamil pointed out, you could stop the recursive remove by the force shutdown in time for some data to survive.

As for why the Fedora had some space used, it depends on how you checked it. Even empty filesystem has some space used (metadata, filesystem reserve etc.) and for example GParted will show this but that doesn't necessary mean some data survived.

5
  • 2
    So, I can conclude that the command: 'sudo rm -rf /*' erases every thing in the root partition, including data in the mounted partitions? And one should never use it! Commented Jun 29, 2021 at 6:43
  • Yes. You can use it if you really want to remove everything, but there are better tools for that. Commented Jun 29, 2021 at 7:04
  • 3
    @AustinRojers "Everything" may be more than you think. In some circumstances rm -rf can brick hardware. Commented Jun 29, 2021 at 7:14
  • Actually it won't remove files or folders in the root folder which start with a dot, but that's quite theoretically. Commented Jun 29, 2021 at 9:50
  • I believe rf -r invokes /bin/rm recursively (although I have not seen this tried since Solaris (SunOS 1.9 or so): maybe Linux is smarter). In SunOS, it would shoot itself in the foot during /bin, which is conveniently early in the alphabet. You might still have sh and tar to restore a backup (assuming you still had a job). Commented Jun 29, 2021 at 10:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.