Recursively remove files

后端 未结 12 2078
無奈伤痛
無奈伤痛 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:13
    cd /var/www/html && find . -name '.DS_Store' -print0 | xargs -0 rm
    cd /var/www/html && find . -name '._*' -print0 | xargs -0 rm
    
    0 讨论(0)
  • 2020-11-30 17:15
    find . -name "FILE-TO-FIND"-exec rm -rf {} \;
    
    0 讨论(0)
  • 2020-11-30 17:16

    Newer findutils supports -delete, so:

    find . -name ".DS_Store" -delete
    

    Add -print to also get a list of deletions.

    Command will work for you if you have an up-to-date POSIX system, I believe. At least it works for me on OS X 10.8 and works for others who've tested it on macOS 10.12 (Mojave).

    Credit to @ephemient in a comment on @X-Istence's post (thought it was helpful enough to warrant its own answer).

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

    You could switch to zsh instead of bash. This lets you use ** to match files anywhere in a directory tree:

    $ rm /var/www/html/**/_* /var/www/html/**/.DS_Store
    

    You can also combine them like this:

    $ rm /var/www/html/**/(_*|.DS_Store)
    

    Zsh has lots of other features that bash lacks, but that one alone is worth making the switch for. It is available in most (probably all) linux distros, as well as cygwin and OS X.

    You can find more information on the zsh site.

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

    It is better to see what is removing by adding -print to this answer

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

    change to the directory, and use:

    find . -name ".DS_Store" -print0 | xargs -0 rm -rf
    find . -name "._*" -print0 | xargs -0 rm -rf
    

    Not tested, try them without the xargs first!

    You could replace the period after find, with the directory, instead of changing to the directory first.

    find /dir/here ...
    
    0 讨论(0)
提交回复
热议问题