Asking for a friend.

Imagine that one has accidentally created a file named ~ and in the process of deleting it, foolishly types:

rm -rf ~

Luckily, I have active terminal windows open, so all is not entirely lost. I happened to have stopped this while it was deleting in the ~/. prefixed directories, too, so I somehow have all my work related content still as those directories didn't get hit with the rm (lucky, I know).

Is there any way to recover from this? What files do I need to recreate while I still have valid terminal sessions?

I'm under the assumption that all my configuration (mostly in ~/. named folders/directories) is permanently gone. I've recovered some of my .bash_profile by looking at env, alias, and typeset -f but I'm sure I'm missing parts of it.

  • 2
    You need to sacrifice a rubber chicken at the alter of Time Machine. Short of that, you can try a recovery utility like DiskDrill but this is not guaranteed. The more you use the drive, the less your chances of recovery.
    – Allan
    Jan 10 '17 at 21:56
  • @Allan my friend says that he doesn't use Time Machine... ;_;
    – enderland
    Jan 10 '17 at 21:57
  • It's time for a new profile and a lesson in the virtues of backup.
    – Allan
    Jan 10 '17 at 21:58
  • 1
    We need a close the question item: "Please restore ... from TM backup."
    – klanomath
    Jan 10 '17 at 21:59
  • 1

rm is one of those dangerous commands where to "Err is human, but to really foul things up, you need a computer." rm immediately deletes the files and bypasses the Trash...you don't pass "Go" and you don't "collect $200."

Your best bet is to....

  1. Stop using the machine as in ASAP. The more your use it, the more disk activity, the less of a chance of recovery.

  2. Look at getting something like DiskDrill. It's free to use but the actual recovery will cost around $100. There are others, but I found this one works really well for me.

  3. Start a Time Machine regimen and adhere to it.

  • Oh, as a software developer I know the danger of rm. My problem was naively trying to delete ~/.mypath/~ with it..
    – enderland
    Jan 10 '17 at 22:06
  • Been there. TM is good, but I created a differencing script that copies my work to the Cloud and to a local NAS and keeps 7 days worth of variations. If I hose things up, I have at minimum two places to get back to.
    – Allan
    Jan 10 '17 at 22:12
  • @enderland: Next time you want to delete a directory with a risky name, first type echo risky_name. For example echo 2 * hotels to see how to use it correctly (here rm -rf './2 * hotels').
    – dan
    Jan 10 '17 at 22:32
  • @danielAzuelos "Ctrl-x" followed by "*" does wildcard expansion; but I'm not sure what happens with the tilde. Hard to test on my phone...
    – Kent
    Jan 11 '17 at 8:18

If you are sure that only files/folder starting with a dot are gone you are actually quite safe. Hardly anything on macOS relies on such files. If you want to recover the defaults, create a new user account and copy any missing stuff from there.

The key issues probably come from the init files of your shell and your ssh configuration. I would assume/hope that you know haw to rebuild them if you are experienced enough to change/use them :-)

PS: it would also be a good opportunity to establish a backup strategy...

  • If you are sure Sure? No. Optimistic though? Yeah.
    – enderland
    Jan 10 '17 at 22:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .