Recursively remove files

后端 未结 12 2077
無奈伤痛
無奈伤痛 2020-11-30 16:52

Does anyone have a solution to remove those pesky ._ and .DS_Store files that one gets after moving files from a Mac to A Linux Server?

specify a start directory and

相关标签:
12条回答
  • 2020-11-30 17:06

    Simple command:

    rm `find ./ -name '.DS_Store'` -rf
    rm `find ./ -name '._'` -rf
    

    Good luck!

    0 讨论(0)
  • 2020-11-30 17:06

    This also works:

    sudo rm -rf 2018-03-*

    here your deleting files with names of the format 2018-03-(something else)

    keep it simple

    0 讨论(0)
  • 2020-11-30 17:07

    Example to delete "Thumbs.db" recursively;

    find . -iname "Thumbs.db" -print0 | xargs -0 rm -rf
    

    Validate by:

    find . -iname "Thumbs.db"
    

    This should now, not display any of the entries with "Thumbs.db", inside the current path.

    0 讨论(0)
  • 2020-11-30 17:10
    find /var/www/html \( -name '.DS_Store' -or -name '._*' \) -delete
    
    0 讨论(0)
  • 2020-11-30 17:12

    if you have Bash 4.0++

    #!/bin/bash
    shopt -s globstar
    for file in /var/www/html/**/.DS_Store /var/www/html/**/._ 
    do
     echo rm "$file"
    done
    
    0 讨论(0)
  • 2020-11-30 17:12

    A few things to note:

    '-delete' is not recursive. So if .TemporaryItems (folder) has files in it, the command fails.

    There are a lot of these pesky files created by macs: .DS_Store ._.DS_Store .TemporaryItems .apdisk

    This one command addresses all of them. Saves from running find over and over again for multiple matches.

    find /home/foo \( -name '.DS_Store' -or -name '._.DS_Store' -or -name '._*' -or -name '.TemporaryItems' -or -name '.apdisk' \) -exec rm -rf {} \;
    
    0 讨论(0)
提交回复
热议问题