I understand I can use find . -name ".DS_Store"
to find all the .DS_Store files in the current folder and all subfolders. But how could I delete them from command line simultaneously? I found it's really annoying to switch back and forth to all folders and delete it one by one.
-
2It's odd ya' know - this voting system I mean. On June 10, 2022, this is a highly-upvoted (159 upvotes) question, and the "top 5" answers have 408 net upvotes. But the [only answer that looks at this question in the broader context](https://stackoverflow.com/a/69836867/5395338) gets less than 1% of the total net upvotes. – Jun 10 '22 at 22:07
-
Related: how to prevent them from being created `defaults write com.apple.desktopservices DSDontWriteNetworkStores true` (and reboot) – norok2 Mar 15 '23 at 10:24
6 Answers
find
can do that. Just add -delete
:
find . -name ".DS_Store" -delete
Extend it even further to also print their relative paths
find . -name ".DS_Store" -print -delete
For extra caution, you can exclude directories and filter only for files
find . -name ".DS_Store" -type f -delete

- 9,187
- 3
- 68
- 108

- 8,162
- 3
- 33
- 40
-
4You need to fix file name case to be **".DS_Store"**, if used ".DS_STORE" it will not work as file names are case sensitive. – Amr Lotfy Aug 14 '16 at 09:24
-
2@AmrLotfy That's not actually true, the default mac file system is case insensitive – Others Oct 23 '16 at 18:41
-
28For extra caution, I usually exclude directories like this: `find . -name '.DS_Store' -type f -delete` – xApple Jul 20 '17 at 11:29
-
I would add this line to my .bashrc_profile, to clean the files every time I start the shell. How do I make it less verbose, or totaly quiet? – Danijel Sep 11 '19 at 12:19
-
@Danijel in general, you can append `2>/dev/null 1>/dev/null` to a unix command to make it quiet. – Samie Bencherif Mar 22 '20 at 19:35
find . -name ".DS_Store" -print -delete
This will delete all the files named .DS_Store
in the current path while also displaying their relative paths

- 16,375
- 6
- 40
- 68

- 1,256
- 12
- 13
-
3
-
1@ppperry, this is automatic message from the review. I voted to delete you answer, because it doesn't add anything important comparing to the accepted one. – kelin Aug 13 '17 at 09:42
-
6
Here is how to remove recursively the .DS_Store
file
Open up Terminal In the command line, go to the location of the folder where all files and folders are:
cd to/your/directory
Then finally, type in the below command:
find . -name '.DS_Store' -type f -delete
Press Enter
Cheers!!
-
Proliferating `cd` superstition is doing the community a disservice. Just provide the name of the directory as the first argument to `find` instead of `.`. See also [What exactly is current working directory?](https://stackoverflow.com/questions/45591428/what-exactly-is-current-working-directory/66860904) – tripleee May 29 '23 at 10:21
You can also use extended globbing (**
):
rm -v **/.DS_Store
in zsh, bash 4 and similar shells (if not enabled, activate by: shopt -s globstar
).

- 155,785
- 88
- 678
- 743
-
I found the problem to be a .DS_Store file in the navigation folder ```grep -r "\x00" app/src/main/res``` and ```rm -v **/.DS_Store``` That solved the problem – display name Oct 13 '22 at 00:51
The best way to do this cleanly is using:
find . -type f \( -name ".DS_Store" -o -name "._.DS_Store" \) -delete -print 2>&1 | grep -v "Permission denied"
This removes the files, hides "permission denied" errors (while keeping other errors), printing out a clean list of files removed.

- 101
- 1
- 5
All the answers above work but there is a bigger problem if one is using mac and still on mac. The described lines do delete all the DS_Store
files but Finder recreates them immediately again because that is the default behaviour. You can read about how this all works here. To quote from there if you are on mac, you should remove them only if you really need:
If you don’t have a particular reason to delete these .DS_Store files (windows sharing might be a solid reason,) it’s best to leave them “as is.” There’s no performance benefit in deleting .DS_Store files. They are harmless files that don’t usually cause any problems. Remember that the .DS_Store file saves your personalized folder settings, such as your icon arrangement and column sortings. And that’s why you normally don’t want to delete them but rather HIDE them.
If you really do, there is one more way which was not mentioned here:
sudo find / -name “.DS_Store” -depth -exec rm {} \;

- 2,143
- 2
- 19
- 47
-
1`"Finder recreates them..."` Good point - I was thinking the same thing as I read through all the fine answers here... it's like killing ants: there are always more of them! In my case, I'm trying to delete `.DS_Store` files that are in my NAS-housed music library - the result of lazy copying and/or `rsync`ing over the years. – Jun 10 '22 at 21:52
-
Plus one, if you do an ordinary `ls` the file will not be listed as it is hidden. – Timo Feb 07 '23 at 16:13