使用shell命令遍历目录和子目录文件并输出到文本

 

 

“input_dir”代表当前目录,“output_file”代表输出文件,你可以自己根据情况修改,

 1 #!/bin/bash
 2 function getdir(){
 3     for element in `ls $1`
 4     do  
 5         dir_or_file=$1"/"$element
 6         if [ -d $dir_or_file ]
 7         then 
 8             getdir $dir_or_file
 9         else
10             echo $dir_or_file >> $output_file
11         fi  
12     done
13 }
14 input_dir="."
15 output_file="out.txt"
16 getdir $input_dir

 

借鉴自此:http://www.cnblogs.com/xiaopipi/p/6214673.html   发博仅为方便以后查看

posted @ 2017-08-03 20:10  WithoutDreams  阅读(2980)  评论(0编辑  收藏  举报