Created
April 21, 2016 07:58
-
-
Save wikier/70043d9b2eed0b259b695ffdf9bc5d2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -ne 1 ]; then | |
echo "missing directory" | |
echo "Usage: ./flat_directory.sh DIR" | |
exit -1 | |
fi | |
DIR=$1 | |
if [ ! -d "$DIR" ]; then | |
echo "Directory '${DIR}' not found" | |
exit -1 | |
fi | |
TARGET="${DIR}-flat" | |
mkdir -p ${TARGET} | |
find ${DIR} -type f -print0 | while IFS= read -r -d $'\0' orig; do | |
dest=${orig//\//_} | |
dest=${dest/$DIR\_/$TARGET\/} | |
echo "copying '${orig}' to '${dest}'..." | |
cp ${orig} ${dest} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment