Potential accidental deletion of empty folders in /Users/(User) directory

I was doing a school assignment which consisted of creating a shell script that deletes empty folders. The problem is that I ran it inside my /Users/(User) folder. It then proceeded to ask permission to access photos, apple music, etc. I denied access to such folders, and was waiting for it to delete JUST the dummy folder I created. I was foolish enough to not run this inside a special folder, and now I am not sure if something important got deleted. It strictly deleted empty folders, and I stopped it on its tracks. I don’t know about any essential empty folders that might be missing. All I want to know if I should be worried or not (I care about my system’s integrity).


[Re-Titled by Moderator]

Original Title: rm’d empty folders

MacBook Air 13″, macOS 15.6

Posted on Aug 14, 2025 04:17 AM

Reply
Question marked as Top-ranking reply

Posted on Aug 14, 2025 02:09 PM

It’s probably benign, if anything happened.


Want to be sure? Restore your backups. Backups are about the only way to mark data as valuable.


As for what happened here, you will have not been able to delete any part of macOS itself, but what else was deletable within the path, nobody here knows.


Having been there myself…


Some operations are best on a test system or from a test login.Everybody has a test system too, though some refer to that as “production”.


I usually prototype shell scripts with ls and not rm, or will use find with ls or echo, or will use the rm -i switch, while testing.


And beware of spaces and other “mayhem” that can await within filenames. If in zsh, have a look at the q modifier.

echo -E ${(q)@}


Also using set -o noglob, and set -u as appropriate, as a means to reduce exposure to some other potentially nasties.

4 replies
Question marked as Top-ranking reply

Aug 14, 2025 02:09 PM in response to ericgzn30

It’s probably benign, if anything happened.


Want to be sure? Restore your backups. Backups are about the only way to mark data as valuable.


As for what happened here, you will have not been able to delete any part of macOS itself, but what else was deletable within the path, nobody here knows.


Having been there myself…


Some operations are best on a test system or from a test login.Everybody has a test system too, though some refer to that as “production”.


I usually prototype shell scripts with ls and not rm, or will use find with ls or echo, or will use the rm -i switch, while testing.


And beware of spaces and other “mayhem” that can await within filenames. If in zsh, have a look at the q modifier.

echo -E ${(q)@}


Also using set -o noglob, and set -u as appropriate, as a means to reduce exposure to some other potentially nasties.

Aug 14, 2025 01:38 PM in response to ericgzn30

We have no idea what may have been deleted because we don't have any script details to judge what may have happened. If you were using "rm" to delete the items, then I would have suggested adding the " -i " option to confirm each & every deletion at least until you have perfected the script. I also personally like to have a script to log all the files involved so I can review it prior actually invoking a destructive command like "rm".


Testing another folder, or perhaps better yet, testing it from a new temporary Standard user account would be wise in order to limit the destructive capabilities until you have verified it is safe to run on your main user account. I also tend to use a VM or a different system for testing certain things so I can keep my main system safe & secure.


You can always restore from a backup made prior to running your script.



Potential accidental deletion of empty folders in /Users/(User) directory

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