显示目录结构的shell脚本

来源:互联网 发布:淘宝卖家快递费用 编辑:程序博客网 时间:2024/06/07 15:05
# !/bin/bashcurrent_path=`pwd`output_dir(){   dir=$1    #dir is a globle varible   elements=`ls $dir`        echo "$2""+"${dir##/*/}    #get the dir name, remove the path   for each in $elements   do      if [ -d $1"/"$each ]      then          output_dir $1"/"$each "$2""    "    #here, dir will be changed, and be used in the outloop      else          echo "$2""    " $each      fi   done}output_dir $current_path ""  # first para is directory, second para is space