0

When using the rm command in OS X 10.9 I accidentally deleted an entire disk.

As I understand the command I used: sudo rm -Rfv /Volumes/Disk/AppName\!\ Whatever\ X.app/Contents/Resources/* everything inside the "Resources" directory will be deleted including folders with files, which is why I used the "R" flag. The "v" did briefly show me files being affected, but I closed the window within a few seconds. It was probably a mistake to use the "f" flag, but without it the problem folder wouldn't be deleted.

Does the given path not limit the command to that directory? How could the command be given in a more safe fashion limiting it to only the content of the path?

The reason I used rm was because the "Resources" directory contained a file that refused to be deleted as it "contained files" that were invisible also when showing invisible files, wouldn't let itself be replaced or put into the trash. It's certainly possible this file somehow pointed back to the entire disk and this is the reason everything was deleted. Does this seem like a likely explanation to you?

I've tested this external disk for errors, but it came back as squeaky clean every time. It's a new 3TB drive.

2 Answers 2

2

When using the rm command in OS X 10.9 I accidentally deleted an entire disk.

I do not see how that command would delete the contents of an entire disk.

As I understand the command I used: sudo rm -Rfv /Volumes/Disk/AppName!\ Whatever\ X.app/Contents/Resources/* everything inside the "Resources" directory will be deleted including folders with files.

Correct.

Does the given path not limit the command to that directory?

It does, and in the example you gave you carefully escaped all the spaces. Now if you did not do and ended up with an unescaped whitespac in the path then the command might have ended up like this:

rm -Rfv /Volumes/Disk/ AppName\!\Whatever\ X.app/Contents/Resources/*.

Notew that I am not saying that you did this, but it is the only thing which I can think of which would delete everything mounted under /Volumes/Disk/

How could the command be given in a more safe fashion limiting it to only the content of the path?

You can first cd to the place where you want to delete the files.

cd /Volumes/Disk/AppName\!\ Whatever\ X.app/Contents/Resources/
rm -Rfv * 

Always be careful when using rm with both recursive and with force (-R and -f). Especially as root (cq sudo'd).

1
  • Thanks for the advice and explanation! I'll remember to use "cd" in the future. That does appear as a much safer route.
    – MiB
    Commented Jun 11, 2015 at 10:05
1

The "rm" command is the same in *nix systems (That includes BSD which OSX is based on)

So see "man rm" for explanation of the switches.

-R means recursive, that means it'll just loop against all the subdirectories to the specified path. Since this command will not transverse against soft links, you can be sure it's limited to the directory.

4
  • Thanks. I read the man pages. I should have mentioned that I was just surprised I got all the content of the disk deleted with this command. I guess the mystery directory was involved somehow. Was my understanding of "*" correct too? It does mean "every file and folder" in this context?
    – MiB
    Commented Jun 11, 2015 at 9:58
  • It means every file and folder. Your shell will expand this to their actual names and feed the result to rm.
    – Hennes
    Commented Jun 11, 2015 at 10:04
  • 1
    When in doubt, run ls -R with same path to see it's affecting range.
    – cheong00
    Commented Jun 11, 2015 at 10:07
  • Actually, you reminded me of an incident that I designed a script to wipe out recycle bin of SMB shared folder daily, and then someone deleted the recycle bin folder themselve, so the script somehow decide it should delete from "/" instead. Later I have to restore the system with backup, plus added a check to see if the folder exist before running "rm -Rf" to it.
    – cheong00
    Commented Jun 11, 2015 at 10:11

You must log in to answer this question.

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