Skip to content

Instantly share code, notes, and snippets.

@techno-tanoC
Created June 5, 2018 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techno-tanoC/10d940b0e8087cddc2619353031b912b to your computer and use it in GitHub Desktop.
Save techno-tanoC/10d940b0e8087cddc2619353031b912b to your computer and use it in GitHub Desktop.
PRE_IFS=$IFS
IFS=$'\n'
path=$1
directories=$(find "$path" -maxdepth 1 -mindepth 1 -type d)
files=$(find "$path" -maxdepth 1 -mindepth 1 -type f)
for f in $files; do
fn=$(basename "$f")
for d in $directories; do
dn=$(basename "$d")
if [[ $fn = *"$dn"* ]]; then
mv "$f" "$d"
fi
done
done
IFS=$PRE_IFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment