bash 遍历目录
bash遍历目录脚本traverse.sh:
#!/bin/bash datadir=$1 declare -a dirlist dirlist=`ls $datadir 2>/dev/null` for i in ${dirlist[@]} do declare -a dirlist1 dirlist1=`ls $datadir/$i 2>/dev/null` for x in ${dirlist1[@]} do
mv $1/$i/$x/* $1/$i done done
运行命令:sh traverse.sh /data/test
/data/test参数为想要遍历的目录。