sudo rm vs. sudo rm -rf

I tried to delete my Documents folder using the sudo rm -rf Documents command in Terminal ( that's not exactly what I typed btw. Just for sake of explanation ) but instead of typing the correct sudo rm -rf line, I left out the -rf part and executed using sudo rm Documents. Couple of questions


1. What exactly did it do by typing in said command


2. I went back to use the correct line sudo rm -rf Documents and the Documents folder is deleted until I go back into Finder when the Documents folder pops back up again.


What I was trying to do was to create the Documents folder in my secondary HDD, delete the original Documents folder on my Boot Drive and create a Symlink to the Documents folder.


Thanks for any help and explanation.


p.s. my computer is running fine for now. I have tried rebooting and it boots fine. Just want to know what I did when I typed in said command.

MacBook Pro, OS X Yosemite (10.10.5)

Posted on Jul 18, 2018 8:04 PM

Reply
Question marked as Top-ranking reply

Posted on Aug 2, 2018 5:05 PM

...I'm unable to sudo rm -rf that folder...

That folder being "Documents"


The following command should specify the permissions on the folder

/bin/ls -dleO@ Documents

Here is what my Documents folder permissions are

drwx------+ 262 me staff - 8908 Jul 24 22:26 Documents

0: group:everyone deny delete

It would appear that Documents has an Access Control List (ACL) entry that denies everyone the ability to delete it.


Which it also appears to prevent everyone from renaming it as well

mv Documents Documents.bob

mv: rename Documents to Documents.bob: Permission denied

You can get around this by using the Nuclear Option (the sudo command). BE VERY CAREFUL when using the 'sudo' command as it runs commands bypassing all the safeties built into the system to protect users from themselves.

sudo mv Documents Documents.saved

Password: your_account_password_which_should_be_the_admin_account

ln -s /Volumes/<your_external_volume>/path/to/Documents Documents

# Make sure everything went as desired

# when you are satisfied, you can remove the original Documents.saved

sudo rm -rf Documents.saved

Similar questions

9 replies
Question marked as Top-ranking reply

Aug 2, 2018 5:05 PM in response to TomsOfDoom

...I'm unable to sudo rm -rf that folder...

That folder being "Documents"


The following command should specify the permissions on the folder

/bin/ls -dleO@ Documents

Here is what my Documents folder permissions are

drwx------+ 262 me staff - 8908 Jul 24 22:26 Documents

0: group:everyone deny delete

It would appear that Documents has an Access Control List (ACL) entry that denies everyone the ability to delete it.


Which it also appears to prevent everyone from renaming it as well

mv Documents Documents.bob

mv: rename Documents to Documents.bob: Permission denied

You can get around this by using the Nuclear Option (the sudo command). BE VERY CAREFUL when using the 'sudo' command as it runs commands bypassing all the safeties built into the system to protect users from themselves.

sudo mv Documents Documents.saved

Password: your_account_password_which_should_be_the_admin_account

ln -s /Volumes/<your_external_volume>/path/to/Documents Documents

# Make sure everything went as desired

# when you are satisfied, you can remove the original Documents.saved

sudo rm -rf Documents.saved

Jul 19, 2018 8:01 PM in response to TomsOfDoom

I do not know what is creating Documents. Is the new Documents folder empty?

/bin/ls -a

If it is not empty, then what is in the Documents folder might give a hint as to what app created.


For the following, make sure you have your Documents copied to the external device


If you goal is to create a symlink to your Documents folder on an external device you can do a simple dance such as the following:

mv Documents Documents.old ; \

ln -fs /Volumes/external_vol_name/path/to/your/external/Documents/folder Documents

rm -rf Documents.old

Jul 24, 2018 7:29 PM in response to TomsOfDoom

What if you do something like


sudo mv Documents Documents.old ; ln -fs /Volumes/external_vol_name/path/to/your/external/Documents/folder  Documents
Password: your_admin_password

As one line, so that you first move Documents out of the way, and then immediately create the symbolic link.


And prefix the mv command with sudo so that you elevate your privileges.

Jul 19, 2018 6:19 AM in response to BobHarris

Thanks for your reply BobHarris.


So then I just have 1 question. I have since then tried to execute the command using the proper line


sudo rm -rf Documents and the Documents folder goes away momentarily but come right back. Would you have any guess as to why this would happen?


I was able to delete my Download folder with the same command no problem.


Thanks again for your reply

Jul 30, 2018 10:35 AM in response to BobHarris

Hey BobHarris


Again, thanks for your response. I'm kind of afraid to try anything until I'm able to figure out what it is that I did when I started this whole mission. Like you said, the command line I entered shouldn't have done anything since it's not a valid command but somehow it made it so that I'm unable to sudo rm -rf that folder.


I'm going to dig in a little deeper to see if I can learn more about it. I wish I would have kept a transcript of the message I got following the command.


Thanks for your help.

Aug 2, 2018 5:05 PM in response to BobHarris

I did everything like you said and it looks like it did everything I was trying to do! I have a new Documents folder on my HDD with symlink on my Boot drive going to the Documents folder on the HDD. I still kept the sudo mv Documents.saved folder on the Boot drive.


Turns out what I wanted was to move my music folder ( which I could have sworn was a subfolder inside the Documents folder ) because that's where all of my large audio files would wind up living from Logic Pro X.


I just went through the regular process of copying/deleting a folder then creating symlink for that so now I have exactly what I need.


Thanks for all your help and suggestions.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

sudo rm vs. sudo rm -rf

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.