shell编程之如何遍历进入当前目录下的所有子目录 | 您所在的位置:网站首页 › apachecommonsiofileutils怎么获得目录及所有子目录 › shell编程之如何遍历进入当前目录下的所有子目录 |
问题: 我想在顶层目录下编写一个脚本来调用自录下的clean.sh文件,该如何实现?
第一种情况: 假设目录结构为: fme/ |__clean.sh |__dc250/clean.sh |__dc300/clean.sh |__dc350/clean.sh 现在我在fme结构下编写一个clean.sh文件调用各个子目录下的clean.sh文件。 实现方法如下: #!/bin/bash for dir in `ls .` do if [ -d $dir ] then echo $dir cd $dir . clean.sh cd .. fidone
这里需要学习的是if的判断语句。 文件表达式if [ -f file ] 如果文件存在if [ -d ... ] 如果目录存在if [ -s file ] 如果文件存在且非空 if [ -r file ] 如果文件存在且可读if [ -w file ] 如果文件存在且可写if [ -x file ] 如果文件存在且可执行整数变量表达式if [ int1 -eq int2 ] 如果int1等于int2 if [ int1 -ne int2 ] 如果不等于 if [ int1 -ge int2 ] 如果>=if [ int1 -gt int2 ] 如果>if [ int1 -le int2 ] 如果 |
CopyRight 2018-2019 实验室设备网 版权所有 |