Skip to content

Instantly share code, notes, and snippets.

@joegaffey
Last active January 1, 2018 14:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joegaffey/cc4350f884a5de5b62e33a33346a3404 to your computer and use it in GitHub Desktop.
Save joegaffey/cc4350f884a5de5b62e33a33346a3404 to your computer and use it in GitHub Desktop.
Sort files into folders by month. Pass file name pattern in a parameter in quotes e.g. '*.jpg'.
#!/bin/bash
months='Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'
echo $months | xargs mkdir
for month in $months
do
ls -l $1 | grep $month | awk '{print $NF}' | xargs -I {} mv {} ./$month
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment