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

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

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

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章