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参数为想要遍历的目录。

posted @ 2017-04-06 11:12  派。  阅读(572)  评论(0编辑  收藏  举报