Skip to content

Instantly share code, notes, and snippets.

@JamieHeather
Last active January 26, 2018 21:28
Show Gist options
  • Save JamieHeather/21ffe7cb5cc46f7f829efbd8250b4f01 to your computer and use it in GitHub Desktop.
Save JamieHeather/21ffe7cb5cc46f7f829efbd8250b4f01 to your computer and use it in GitHub Desktop.
Tidy up a directory of ISO 8601 dated files
# Goes through directory of appropriately named files and decants into labeled year-month gzipped tarball archives
# Files MUST be dated in ISO format in filename, i.e. YYYY-MM-DD
# Currently set up to only work from 2010-2019; add extra loops for decades(/centuries etc) as needed
# First get rid of pesky spaces in names (which mess up the xargs command)
find -name "* *" -type f | rename 's/ /_/g'
# Then loop through desired files and sort into appropriate tarbals
for y in {1..9}
do
for mo in {01..12}
do
# Get the year
m=$(printf "%02d" $mo)
ym="201$y-$m"
echo $ym
# Tarball the desired files
ls *$ym* | xargs tar -cvzf $ym.tar.gz
# Remove the originals
rm *$ym*
# NB greater specificity could be added to the regex, e.g. '$ym*.jpg' would just sort jpg files
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment