file_dir=`find 目录 -mindepth 1 -maxdepth 5 - type d`
for dir in $file_dir
do
file_name=`basename $dir`
if [ $file_name != "目标文件名" ];then
rm -rf $dir
if [ $? != 0 ];then
echo "未删除成功!"
exit -2
fi
fi
done
本文介绍了一种使用find命令结合bash脚本的方法,用于在指定目录下批量删除除特定文件名以外的所有子目录,同时提供了错误处理机制。
file_dir=`find 目录 -mindepth 1 -maxdepth 5 - type d`
for dir in $file_dir
do
file_name=`basename $dir`
if [ $file_name != "目标文件名" ];then
rm -rf $dir
if [ $? != 0 ];then
echo "未删除成功!"
exit -2
fi
fi
done
转载于:https://www.cnblogs.com/ivyharding/p/11235823.html

被折叠的 条评论
为什么被折叠?