Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete .DS_STORE files in current folder and all subfolders from command line on Mac

People also ask

Can I delete DS_Store files on Mac?

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.

How do I delete files in subdirectories?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.


find can do that. Just add -delete:

find . -name ".DS_Store" -delete

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


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.


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!!


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).