Need help in bash script and awk command

前端 未结 2 1038
滥情空心
滥情空心 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.

    0 讨论(0)
  • 2021-01-27 06:43
    awk -F"/" '{
        print "\n planet=", $2, "\n category=", $3, "\n sub cat=", $4
        for (i = 5; i < NF; i++) print " add cat=", $i
        print " Name=",$NF
    }'
    
    0 讨论(0)
提交回复
热议问题