目录遍历脚本
[root@NewCDH-0--144 opt]# cat dir.sh
#!/usr/bin/sh
DIR=$(cd "$(dirname "$0")"; pwd)
echo "当前目录:$DIR"
ROOT=$DIR
for file in $ROOT/*
do
if [ -d "$file" ]
then
echo "$file"
cd $file
#pwd & git status
fi
done
[root@NewCDH-0--144 opt]# ll
total 20
-rw-r--r-- 1 root root 337 Feb 25 13:20 back_log.sh
drwxr-xr-x. 4 cloudera-scm cloudera-scm 39 Mar 15 2018 cloudera
-rw-r--r-- 1 root root 189 Mar 7 13:02 dir.sh
drwxr-xr-x 4 root root 109 Aug 29 2018 falcon-agent
drwxr-xr-x 3 root root 85 Dec 3 17:17 flink
drwxr-xr-x 2 root root 4096 Mar 4 18:29 majihui
drwxr-xr-x 4 root root 4096 Oct 16 10:14 mysql
-rw-r--r-- 1 root root 144 Jan 31 18:14 test.txt
drwxr-xr-x 2 root root 49 Nov 7 17:12 zabbix
[root@NewCDH-0--144 opt]# sh dir.sh
当前目录:/opt
/opt/cloudera
/opt/falcon-agent
/opt/flink
/opt/majihui
/opt/mysql
/opt/zabbix