Skip to content

Instantly share code, notes, and snippets.

@wikier
Created April 21, 2016 07:58
Show Gist options
  • Save wikier/70043d9b2eed0b259b695ffdf9bc5d2b to your computer and use it in GitHub Desktop.
Save wikier/70043d9b2eed0b259b695ffdf9bc5d2b to your computer and use it in GitHub Desktop.
#!/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