Flatten a folder structure to a file name in Bash
This might work for you:
find . -type f -name "*.png" | sed 'h;y/\//_/;H;g;s/\n/ /g;s/^/cp -v /' | sh
find -type f -name '*.png' -printf '%P\0' | \
while read -d $'\0' i ; do cp "$i" "${i////_}" ; done
Where:
%P
tellfind
to omit the leading./
;\0
tellfind
to print the paths using theASCII NUL
character as separator (this should avoid problems with strange names);-d $'\0'
tellbash
to use the proper delimiter for reading the paths;${i////_}
tellbash
to replace every occurrences of/
with_
in the path.
Warning:
This pipeline may involve file overwrites, make sure to take the proper precautions.