如何递归遍历目录以删除具有某些扩展名的文件 [英] How to loop through a directory recursively to delete files with certain extensions
本文介绍了如何递归遍历目录以删除具有某些扩展名的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要递归遍历目录,并删除所有扩展名为.pdf
和.doc
的文件.我设法递归遍历目录,但没有设法过滤具有上述文件扩展名的文件.
I need to loop through a directory recursively and remove all files with extension .pdf
and .doc
. I'm managing to loop through a directory recursively but not managing to filter the files with the above mentioned file extensions.
到目前为止我的代码
#/bin/sh
SEARCH_FOLDER="/tmp/*"
for f in $SEARCH_FOLDER
do
if [ -d "$f" ]
then
for ff in $f/*
do
echo "Processing $ff"
done
else
echo "Processing file $f"
fi
done
由于我什么都没得到,我需要帮助来完成代码.
I need help to complete the code, since I'm not getting anywhere.
推荐答案
find
就是为此而设计的.
find /tmp -name '*.pdf' -or -name '*.doc' | xargs rm
这篇关于如何递归遍历目录以删除具有某些扩展名的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文