linuxmacoscommand-line

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


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.


Solution

  • 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