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.
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.