cd base_dir find -type f > ../list1 edit list1 to remove leading "./" cp ../list1 ../list2 edit list2 to s?/?_?g mvlist ../list1 ../list2 > do . do find -type d -print0 | xargs -0 rmdir #repeat until all dirs gone