Need help in bash script and awk command

前端 未结 2 1039
滥情空心
滥情空心 2021-01-27 06:06

I need a bash script to print folder names and file names recursively (in stdo/p). For example: i have a folders structure like /earth/plants/flowers/rose/rose.jpg.



        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-27 06:24

    You could try this - chock full of bashisms, won't work in other shells:

    (find command goes here) | while IFS=/ read root planet category rest; do

        echo "planet=$planet"
        echo "category=$category"
        size="$(stat -c %s "/$planet/$category/$rest")"
        while [[ "$rest" == */* ]]; do
           subcat="${rest%%/*}"
           rest="${rest#*/}"
           echo "subcategory=$subcat"
         done
         echo "name=$rest"
         echo "size=$size"
         echo
    done
    

    Also, -name "*" on a find command is redundant. But you probably want -type f at least.

提交回复
热议问题