Skip to content

Instantly share code, notes, and snippets.

@ArneAnka
Last active June 30, 2019 11:44
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 ArneAnka/051571f0306c52a9aeccc4c6eee28448 to your computer and use it in GitHub Desktop.
Save ArneAnka/051571f0306c52a9aeccc4c6eee28448 to your computer and use it in GitHub Desktop.
Find images, and copy or move them
# Two scripts that do the same thing a little different, notice `mv` and `cp`. Your choice
# What will happen is that find will recursivly serach the current folder for images, read when
# the file was created, and move/copy it to a corresponding folder.
# This is from https://apple.stackexchange.com/questions/280252/recursively-search-for-images-and-move-them-to-a-date-folder
# http://unix.stackexchange.com/a/83838
find -E . -regex '.*\.(jpg|JPG|png|PNG|jpeg|JPEG|bmp|BMP)' | while read file; do
ts=$(stat -f '%Sm' -t '%Y-%m-%d' "$file")
folder="/Users/username/Documents/Backup_images/$ts"
[[ -d "$folder" ]] || echo mkdir "$folder"
echo cp "$file" "$folder/"
done
# http://unix.stackexchange.com/a/15309
find ./ -type f \( -iname \*.jpg -o -iname \*.png -o -iname \*.bmp -iname \*.jpeg \) | while read file; do
ts=$(stat -f '%Sm' -t '%Y-%m-%d' "$file")
folder="/Users/username/Documents/Backup_images/$ts"
[[ -d "$folder" ]] || echo mkdir "$folder"
echo mv "$file" "$folder/"
done
# Just remove the `echo` from the script, to let them do their thing
@ArneAnka
Copy link
Author

ArneAnka commented May 11, 2017

To search for files in a specific file size: find . -name "*.png" -size -160k. This searches for files under 160k, if you would like to search for files exactly 160k you will do find . -name "*.png" -size 160k, notice the lack of the - before the actual size.

@ArneAnka
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment