Skip to content

Instantly share code, notes, and snippets.

@pavgup
Last active September 15, 2018 21:56
Show Gist options
  • Save pavgup/00e211fda40167752dbe017c46870d9b to your computer and use it in GitHub Desktop.
Save pavgup/00e211fda40167752dbe017c46870d9b to your computer and use it in GitHub Desktop.
Moving all jpegs to a single directory
### The first line simply moves the files using their existing filenames, if there is a complex tree structure with the same filenames, you overrwrite fies
find . -type f -exec file --mime-type {} \; | awk '{if ($NF == "image/jpeg") {split($0,a,":"); print a[1]}}' | xargs -I{} cp '{}' /Users/pavan/Dental/all-images
### The second line adds complexity by grabbing random strings and dropping renaming the copied files randomly:
find . -type f -exec file --mime-type {} \; | awk '{if ($NF == "image/jpeg") {split($0,a,":"); print a[1]}}' | xargs -I{} sh -c 'cp "{}" /Users/pavan/Dental/all-images/$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 64).jpg'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment