Skip to content

Instantly share code, notes, and snippets.

@mfehr
Last active April 24, 2020 14:42
Show Gist options
  • Save mfehr/5a2ca084cd22af4cfb3549283c300343 to your computer and use it in GitHub Desktop.
Save mfehr/5a2ca084cd22af4cfb3549283c300343 to your computer and use it in GitHub Desktop.
Move all files in tree to root folder, delete all subfolders and auto-remove all duplicate files.
#!/usr/bin/env bash
find $1 -type f -exec mv --backup=numbered -t $1 {} +
find $1 -type d -empty -delete
fdupes -rdNS $1
# Sources:
# - https://superuser.com/questions/658075/how-do-i-move-files-out-of-nested-subdirectories-into-another-folder-in-ubuntu
# - https://unix.stackexchange.com/questions/8430/how-to-remove-all-empty-directories-in-a-subtree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment