Last active
December 18, 2015 07:19
-
-
Save ncherro/5746111 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
SRC=~/Pictures | |
DST=~/Pictures-flat | |
# 1. Recursively finds all files ending in .jpg, .jpeg, .cr2 and .png in the | |
# $SRC directory (extension search is case-insensitive) | |
# | |
# 2. Gets each file's date created and creates a YYYY-MM-DD directory in the | |
# $DST directory | |
# | |
# 3. Copies the file into it's $DST/YYYY-MM-DD directory, preserving it's | |
# original created / modified dates and not overwriting existing files | |
while IFS= read -r -u3 -d $'\0' filename; do | |
# get the date created | |
fdate=$(stat -t %Y-%m-%d "$filename" | awk '{print $12}' | sed s/\"//g); | |
d="$DST/$fdate" | |
# create a date created directory | |
if [ ! -d "$d" ]; then | |
mkdir -v "$d" | |
fi | |
# copy | |
# -n do not overwrite existing file | |
# -p preserve created / modified dates | |
# -v verbose | |
cp -npv "$filename" "$d"; | |
done 3< <(find $SRC -type f \( -iname '*.jpg' -o -iname '*jpeg' -o -iname '*.cr2' -o -iname '*.png' \) -print0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment