Skip to content

Instantly share code, notes, and snippets.

@rchrd2
Last active November 25, 2020 04:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
archive files based on creation date
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 *
@rchrd2
Copy link
Author

rchrd2 commented Oct 25, 2020

Looks like it's not working with files that have spaces in the names..

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