遍历同级所有子目录并找出所需的文件或文件夹

来源:互联网 发布:sql union后字段为空 编辑:程序博客网 时间:2024/05/21 09:14

遍历同级所有子目录并找出所需的文件或文件夹

最近有个需求,寻找同级子目录下所有相关的文件夹,由于目录太多复杂,所以决定用脚本来实现,下面是具体的实现过程。

touch lustre1-user.txt

for file in `find /data -maxdepth 1 -mindepth 1 `                    #寻找所有/data下的子目录

do

if [ -d $file/workplace1 ]                                                               #判断该文件或者文件夹是否存在

then

ls -l $file/workplace1 | grep -v /lustre/ >>lustre1-user.txt      #把串中没有/lustre/的输出到/lustre1-user.txt

elif [ -d $file/workplace ]

then

ls -l $file/workplace |grep -v /lustre/>>lustre1-user.txt            #再以同样的方式来查找另外一个目录

fi

done


原创粉丝点击