Find folders & subfolders containing only '.DS_Store'

Through Terminal or otherwise, how can I find all subfolders in a folder/directory containing only the item ‘.DS_Store’?


I want to remove these. I’ve tried deleting .DS_Store through different Terminal commands and then using Spotlight to find files containing zero (and less than 1) items and have located some, but not all.


Thank you!

Mac mini, OS X Mountain Lion (10.8.2)

Posted on May 20, 2013 7:08 AM

Reply
10 replies

May 20, 2013 7:35 AM in response to Susan Swartz1

Empty folders will be the only ones that contain only a .DS_Store file, so just search for empty folders, and then remove them. To do this, in the Finder press Command-F to bring up the Find window. Then choose "This Mac" as the primary search location, followed by setting the default "Kind" criterion to "Folder."


Next, click the plus button to the far right and in the new filter that appears, select "Other" from the drop-down menu. In this menu, search for "Number of Items" and add this as the filter to use. In here, set it to "equals" and "0" as the number of items, and you will then see all the empty folders on your system. You can then peruse through them and see if they are user folders or system folders, and delete them if desired.


Be sure you do not remove any system folders, even if they are empty.


To narrow the search results, you can perform this search by first opening your home directory and then pressing Command-F, so you will have this as the starting point of your search (and therefore not include system files), but be sure you click the name of the starting folder next to "This Mac" instead of clicking "This Mac" itself. You will then need to perform this more narrowed search on attached external hard drives or secondary boot volumes to find empty folders in there.

May 20, 2013 7:48 AM in response to macjack

Oops. macjack & Topher, I accidentally left something out. These folders are a mess being the result of backups & recovered & duplicates & crashes & who knows what else, now mushed together.


macjack, how do I specifically set Onyx to remove the .DS_Store files from one certain folder (& I apologize if too basic), & not remove other stuff?


Topher, that doesn't seem to work, my layperson guess being that it's because of the mess I made. I'll try doing a new Spotlight index, & then try again. Please also give me some other suggestions, though…


I've previously seen how helpful both of you are.


Thanks,


— Susan

May 20, 2013 8:15 AM in response to Susan Swartz1

Susan Swartz1 wrote:



macjack, how do I specifically set Onyx to remove the .DS_Store files from one certain folder (& I apologize if too basic), & not remove other stuff?

It's in the inreface under Maintenence. The can designate the path and choose for "this folder only" or recursively...

User uploaded file

Note that I rarely suggest use of these so-called maintenance utilities and really hope you use it for nothing more than .ds_stores.

May 20, 2013 8:24 AM in response to Susan Swartz1

Just to note a couple of things:


1) You shouldn't even be seeing these files. Copy/paste the following two commands in Terminal to hide files you aren't supposed to see from the desktop.


defaults write com.apple.finder AppleShowAllFiles FALSE


killall Finder


2) Deleting .DS_Store files is a waste of time (which QuickTimeKirk already said). The OS creates them in each folder to keep track of where the folder is positioned on the screen, it's size and view option. As many times as you delete them, the OS will just keep recreating them.

May 28, 2014 12:29 PM in response to Kurt Lang

You did not read the OP's request. He wants to remove all empty folders, and often this will be a folder that is empty except for .DS_Store. It is reasonable to want to clean up unused folders that house only this metadata.


I was led here trying to find a way around trying to delete them with a script that looks for empty folders, however it won't work becaue they aren't really empty.

May 28, 2014 12:35 PM in response to osbjmg

You reopened a year old topic just so you could admonish someone?


No, you shouldn't be removing empty folders anyway. The OS and apps that create them use them for temp files and other reasons, such as preference settings (different from the application .plist files). Empty doesn't always automatically mean not being used. Unless you know they're dead, leave them alone.

May 28, 2014 6:14 PM in response to Kurt Lang

I'm just keeping things factual, I'm sorry if you took it as a negative comment. It is true that the OP wanted to remove (otherwise) empty folders.


So in my ~/Downloads/ folder, I do not want to leave all the folders there I download files for work daily, and they are numerous in number and usually large. I have a script which deletes files accessed over 60 days ago, and empty folders. I have thousands of folders that have had their contents removed, but the directory is still cluttered. Eventually you actually can run out of inodes on a disk, so it's fine to delete folders in this case.


This thread helped me figure out what I needed and it now works as I hoped.


Script for reference:


#~/Library/LaunchAgents/com.myname.reaper.plist calls this script

#using launchd to run 1x a day at 10:00

#`

#!/bin/sh

# Finds all files within ~/Cases/ whose "last accessed"

# dates are more than 120 days ago and moves them to the trash.

#

# Finds all files within ~/Downloads/ whose "last accessed"

# dates are more than 60 days ago and moves them to the trash.



date

echo $TIME

find ~/Documents/Cases/ -atime +120 -print

find ~/Documents/Cases/ -empty -print

find ~/Downloads/ -atime +60 -print

find ~/Downloads/ -empty -print

find ~/Downloads/ -type f -name ".DS_Store" -print

find ~/Documents/Cases/ -atime +120 -exec mv {} ~/.Trash/ \; ;

find ~/Documents/Cases/ -empty -exec mv {} ~/.Trash/ \; ;

find ~/Downloads/ -atime +60 -exec mv {} ~/.Trash/ \; ;

find ~/Downloads/ -type f -name ".DS_Store" -exec mv {} ~/.Trash/ \; ;

find ~/Downloads/ -empty -exec mv {} ~/.Trash/ \; ;

echo __________________________________________

echo $TIME


say -v Zarvox "reaper complete"

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.

Find folders & subfolders containing only '.DS_Store'

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