Skip to content

Instantly share code, notes, and snippets.

@rchrd2
Last active November 25, 2020 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rchrd2/5bf40a17f3b9887a93d3c244d1ce0b3a to your computer and use it in GitHub Desktop.
Save rchrd2/5bf40a17f3b9887a93d3c244d1ce0b3a to your computer and use it in GitHub Desktop.
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