How to recursively delete multiple files with different extensions?

时光怂恿深爱的人放手 提交于 2019-12-05 14:47:09
find . \( -name "*.extension1" -o -name "*.extension2" \) -type f -delete

find Documents ( -name ".py" -o -name ".html" ) -exec file {} \;

OR

find . -regextype posix-egrep -regex ".*\.(extension1|extension2)$" -type f -delete

Just add more options. A regex solution can also apply but this one's better and safer.

find . \( -name '*.ext1' -or -name '*.ext2' \) -type f -delete

Edit: You probably need -or as well. Before deleting, test it first without the -delete option. (2) Added a pair of () as suggested by gniourf_gniourf.

Maybe regexp will help you

find . -regextype posix-awk -regex "(.*.ext1|.*.ext2)" -type f -delete

This simple command will delete all the files with extension1 and extension2 recursively in that directory. rm find . -name *.extension1 -o -name *.extentions2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!