0

I know that rm -rf /deletes everything in the root directory. How does it work? To be more specific, when the files are getting deleted, won't the files associated with the 'deleting process' or the core files that execute the command get affected and crash?

5
  • 3
    Have a look at David Hoelzer's answer and then Oli's answer.
    – GagandeepT
    Nov 15 '19 at 4:17
  • @GagandeepT Thank you!! It solved all my doubts. :)
    – Moses Kim
    Nov 15 '19 at 4:24
  • 2
    Is the backslash a typo? Did you mean rm -rf /?
    – Kusalananda
    Nov 15 '19 at 6:49
  • 2
    This already has been answered pretty much everywhere, but still want to comment on this part in case someone may miss it: when the files are getting deleted, won't the files associated with the 'deleting process' or the core files that execute the command get affected and crash? Executables are loaded and executed from memory. So "running" command ( or copy in memory ) can delete its own file on disk with no problems Nov 15 '19 at 8:29
  • 1
    Also, the POSIX filesystem semantics say that when a file that is being used is deleted, the process that is using the file can keep using it as normal, but the file will no longer be visible in the directory. The deletion is actually completed after the process closes the file (for any reason, including the process crashing). So even if the 'deleting process' needed something from the disk, as long as it has the file already open when the file gets deleted, it can still get what it needs. But once the deleted-but-still-open file is closed, it will be cleaned up by the filesystem driver.
    – telcoM
    Nov 15 '19 at 10:42

Browse other questions tagged or ask your own question.