You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
hacks/bin/file-by-date

23 lines
625 B

#!/bin/bash
set -x
for FN in *; do
if [[ -f "$FN" ]]; then
MTIME="$(stat -f "%Sm" "$FN")"
if [[ ! -z "$MTIME" ]]; then
# eg "Sep 13 05:02:26 2019"
YYYY="$(date -j -f "%b %d %T %Y" "$MTIME" "+%Y")"
MM="$(date -j -f "%b %d %T %Y" "$MTIME" "+%m")"
DD="$(date -j -f "%b %d %T %Y" "$MTIME" "+%d")"
TD="${YYYY}/${YYYY}-${MM}/${YYYY}-${MM}-${DD}"
if [[ ! -d ./"$TD" ]]; then
mkdir -p ./"$TD"
fi
if [[ ! -e ./"${TD}"/"$FN" ]]; then
mv ./"$FN" ./"$TD"/"$FN"
echo mv ./"$FN" ./"$TD"/"$FN"
fi
fi
fi
done