使用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   發博僅為方便以后查看


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM