Search code examples
macosshellvimzshrm

What does the directory `//` in the shell command `rm -rf //` do, precisely?


I accidentally ran this command while trying to remove an errant directory named \\ from my project directory. Quite a mistake I know. It pretty quickly began hitting permissioned files at which point I realized my mistake so I ctrl-c'ed out of there. I have all my important projects backed up but the command killed my development environment. Opening vim anywhere is crashing and throwing a segfault like so:

Vim: Caught deadly signal SEGV

Error detected while processing function <SNR>130_PollServerReady[7]..<SNR>130_Pyeval:Vim: Finished.

line    4:
Exception MemoryError: MemoryError() in <module 'threading' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.pyc'> ignored
[1]    6921 segmentation fault  vim ~/dotfiles/.vimrc

My primary question for myself and anyone who commits a similar gaff is:

What, precisely does the double backslash // point to? What would be deleted first? Is there a logical first place to begin replacing util, configs, $PATH stuff etc?

Hopefully, this is clear and specific enough for SO.


Solution

  • cd // will take you to the root directory /.

    rm performs a depth-first search, walking the results of the xfts_open call. find also traverses filesystems in this manner.

    find / will list the files that exist. You can then use your knowledge of the expected structure to reverse the list that are missing.

    Alternatively, you can use debugfs to help you get at the files.

    This assumes that these commands will actually work. Realistically, your system is probably hosed. Deleting things in / will break your computer. Restoring from backup is probably the easiest way to return to a functional system. You can also try various utilities to recover recently erased files from your hard drive; if you plan on doing this, you should stop using your computer, as your hard drive currently treats many areas as free space (since you told it to) which recently held files in / and it could start writing to those areas.