Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Find empty folders and accurate Spotlight search results

I’m trying to find empty folders preferably through Spotlight (searching for ‘Kind:Folders’ with ‘Number of items equals zero’), and not including anything relating to Time Machine backups. When I do this, I get results of none even though review of individual Finder windows occasionally shows folders that are in fact empty.


As background, my internal hard drive has items transferred from various sources including files originally on a different computer, and a network and/or external drive.


I’ve tried changing ownership and permissions through both Terminal and the Get Info window, and using the criteria ‘Number of items equals one’ and ‘Number of items is less than one.’


Does it make a difference whether System Preferences/Sharing is on or off?


Is there presently a way to find empty folders?


(I’ve previously posted a similar question, and I’ve also reviewed similar discussions in this forum.)


Thank you!

Mac mini, OS X Mavericks (10.9.1)

Posted on Apr 2, 2014 8:49 AM

Reply
3 replies

Apr 2, 2014 10:44 AM in response to Susan Swartz1

What is your actual aim? Are you hoping to delete these items or make a list etc?


Sharing shouldn't affect the contents of the folders unless another machine is writing or editing files within the shared folders. Turn it of if it concerns you.


Are you just using Spotlight in Finder or are you using the mdfind command in terminal?


Spotlight will not find a lot of files - some system files are excluded from being shown to users with no permissions to edit the files etc.


You are better off using the 'find' command, or 3rd party apps like FindAnyFile (I haven't used this, so you'll need to search).


In Terminal…

find /Users/username/ -empty

Will find 'empty' files & folders in a user account, find also respects permissions, so you need to use sudo to see inside folders you don't own etc.


Use the -type d argument to only find folders, e.g.

find /Users/username/ -empty -type d



Please explain a little about what you hope to achieve, if it's just deleting the folders please take care, some apps will fail if they don't have the right folders already for them. Also modifying permissions on a mass scale is risky, if you don't have permission to do something, you may well be doing it wrong.

Apr 2, 2014 5:48 PM in response to Susan Swartz1

Empty folders take a tiny amount of space (4kb if I recall correctly). They also do little damage to the system however if you are really sure about this the find command has the '-delete' argument.



find /Users/username/ -empty -type d -delete

That will remove ALL found empty folders inside the users/username folder. I really don't recommend this.


A better approach is to create a list (use find without the delete option). Then manually edit that list so that it only includes items you know you don't need. Then paste the 'remove' command at the start of each line so you can paste those lines into Terminal to remove the desired files.


e.g. the list will look like…

rm -ri /Users/username/emptyfolder1

rm -ri "/Users/username/empty folder2"

rm -ri "/Users/username/empty folder3"


note spaces in file paths need quotes (as does most other non alpha-numeric characters).


Please take a full backup before you do any mass deleting, you may find that things slowly fall apart after a few days if you delete a lot of empty folders that were needed by some rarley used task. Restoring them will be painful unless you keep a list of what was removed.


Good luck.

Find empty folders and accurate Spotlight search results

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