Recursively remove files

2019-01-09 22:07发布

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 let it go? like /var/www/html/ down...

标签: linux bash
12条回答
欢心
2楼-- · 2019-01-09 22:58

Newer findutils supports -delete, so:

find . -name ".DS_Store" -delete

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,

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

查看更多
不美不萌又怎样
3楼-- · 2019-01-09 22:58
cd /var/www/html && find . -name '.DS_Store' -print0 | xargs -0 rm
cd /var/www/html && find . -name '._*' -print0 | xargs -0 rm
查看更多
别忘想泡老子
4楼-- · 2019-01-09 22:58
find . -name "FILE-TO-FIND"-exec rm -rf {} \;
查看更多
欢心
5楼-- · 2019-01-09 23:00

Simple command:

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

Good luck!

查看更多
该账号已被封号
6楼-- · 2019-01-09 23:00

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.

查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-09 23:00

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 {} \;
查看更多
登录 后发表回答