archive files based on creation date
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
archive() { | |
if [ ! -d "$1" ]; then echo Missing base; return 1; fi | |
local BASE=$1 | |
for f in "${@:2:$#-1}"; do | |
if [ -d "$f" ]; then continue; fi; | |
local DATE=`date -r "$f" "+%Y-%m-%d"` | |
local YEAR=`date -r "$f" "+%Y"` | |
local TARGET_DIR="$BASE/$YEAR/$DATE" | |
mkdir -p $TARGET_DIR | |
echo cp -iv "$f" "$TARGET_DIR/" | |
cp -iv "$f" "$TARGET_DIR/" | |
done | |
} | |
export -f archive | |
# $ yes n | archive ~/Desktop/msc/media /Volumes/H4N_SD/STEREO/**/* | |
# $ archive ~/archive myfile.wav | |
# > myfile.wav -> ~/archive/2020/2020-10-15/myfile.wav | |
# # $ archive ~/archive * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like it's not working with files that have spaces in the names..