Last active
June 30, 2019 11:44
-
-
Save ArneAnka/051571f0306c52a9aeccc4c6eee28448 to your computer and use it in GitHub Desktop.
Find images, and copy or move them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 dofind . -name "*.png" -size 160k
, notice the lack of the-
before the actual size.