Skip to content

Instantly share code, notes, and snippets.

@sirianni
Created August 20, 2017 00:07
Show Gist options
  • Save sirianni/9739b345bee072a4bfaa5b3de3019ea1 to your computer and use it in GitHub Desktop.
Save sirianni/9739b345bee072a4bfaa5b3de3019ea1 to your computer and use it in GitHub Desktop.
Organize files into subdirectories by year
#!/bin/bash
for f in `ls -p | grep -v /`; do
file="$f"
modtime=`stat --format=%Y "$file"`
year=`date --date @$modtime +%Y`
if [ ! -d "$year" ]; then
mkdir -p "$year"
fi
echo "Moving $file to $year..."
mv "$file" "$year/"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment