Skip to content

Instantly share code, notes, and snippets.

@joegaffey
Last active January 1, 2018 14:03
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/1c477b4c9210153cbc6cd9fb2f1a6683 to your computer and use it in GitHub Desktop.
Save joegaffey/1c477b4c9210153cbc6cd9fb2f1a6683 to your computer and use it in GitHub Desktop.
Sort files into folders by month number. 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)
monthNums='01 02 03 04 05 06 07 08 09 10 11 12'
echo $monthNums | xargs mkdir
i=0
for monthNum in $monthNums
do
ls -l $1 | grep ${months[$i]} | awk '{print $NF}' | xargs -I {} mv {} ./$monthNum
let "i++"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment