Skip to content

Instantly share code, notes, and snippets.

@DmitryMyadzelets
Created September 18, 2024 08:35
Show Gist options
  • Save DmitryMyadzelets/0b9e8f256e9b62a7677764974a17d0c8 to your computer and use it in GitHub Desktop.
Save DmitryMyadzelets/0b9e8f256e9b62a7677764974a17d0c8 to your computer and use it in GitHub Desktop.
Manipulate w lots of files (e.g. images)

Remove every image which name contains 32 symbols after the "-" symbol:

find . -type f | grep -E '*-.{32}.jpg' | xargs rm -f

Convert PNG to JPG:

find . -type f | grep -E '*.png' | xargs -n 1 bash -c 'convert "$0" "${0%.*}.jpg"'

Resize images:

find . -type f -size +3M | grep -E '*.jpg' | xargs -n 1 bash -c 'convert -resize 30% "$0" "${0%.*}.resized"'
find . -type f -size +3M | grep -E '*.jpg' | xargs rm -f
find . -type f | grep -E '*.resized' | xargs -n 1 bash -c 'mv "$0" "${0%.*}.jpg"'

Delete empty directories:

find . -type d -empty -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment