Skip to content

Instantly share code, notes, and snippets.

@jeremy-rutman
Last active March 19, 2022 13:43
Show Gist options
  • Save jeremy-rutman/b6fe2aaef94e2b09d0625f46a9df9a57 to your computer and use it in GitHub Desktop.
Save jeremy-rutman/b6fe2aaef94e2b09d0625f46a9df9a57 to your computer and use it in GitHub Desktop.
get e.g. all .jpgs in a dir and subdirs, copy or delete them
# sed 's\.*/\\' cuts anything before the final forward slash , leaving filename without path
for f in $(find . -name '*.jpg'); do echo $f;echo $f|sed 's\.*/\\' ;cp $f $(echo $f|sed 's|.*/||'); done
#or e.g. only .jpgs larger than 10k and put in specific dir
for f in $(find /path/to/dirwithsubdirs/ -name '*mark.png' -size +10k ); do echo $f;echo $f|sed 's|.*/||' ;cp $f /path/to/destiny/data_logos/$(echo $f|sed 's\.*/\\'); done
#dont clobber extant files, by using cp --backup=numbered
for f in $(find /path/to/dir -name '*.jpg'); do cp --backup=numbered $f pics/$(echo $f|sed 's|.*/||'); done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment