#!/bin/bash
#                        /usr/local/bin/flatten
#  http:///crystalfaeries.net/posix/bin/flatten
# celeste:crystalfaery 2016-06-10 04:01:29+00:00
# Flatten a hierarchy below this directory into this directory
# renaming paths to replace "/" with "."
/usr/local/bin/fdedupe -f	# normalize file names and link duplicates
parent=`pwd`
for d in `find . -mindepth 1 -depth -type d | sed 's/^\.\///'`
do
	cd	${parent}/${d}
		for f in `find . -maxdepth 1 -type f | sed 's/^\.\///'`
		do
			rsync -auvzH ${f} ../`basename $(pwd)`.${f} && rm ${f}
		done
	cd	${parent}
	rmdir	${parent}/${d}
done
cd ${parent}


syntax highlighted by Code2HTML, v. 0.9.1