Skip to content

Instantly share code, notes, and snippets.

@dbernheisel
Created February 21, 2015 04:51
Show Gist options
  • Select an option

  • Save dbernheisel/2016d57e529704a5fb5d to your computer and use it in GitHub Desktop.

Select an option

Save dbernheisel/2016d57e529704a5fb5d to your computer and use it in GitHub Desktop.
Flatten a folder hierarchy.
#!/bin/bash
# Usage: execute flatten-folders.sh while in the directory you want to flatten.
# This will move all content in subdirectories down to present directory
CURRENTDIR="$( cd "$( dirname "$0" )" && pwd)"
for f in "$CURRENTDIR"
do
parentdir="$(dirname "$f")"
find "$f/" -iname '*.*' -exec mv -v \{\} "$parentdir/" \;
rmdir -v "$f"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment