Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Organizes files based on their Modify date.
- # folder structure is YYYY/MMDD/filename
- FILE_ROOT=/path/to/files
- FILES=$FILE_ROOT/*
- for f in $FILES
- do
- # Skip if this is a directory or an executable (Assumes the script is in the same folder)
- if ! test -d "$f" && ! test -x "$f"; then
- month=`stat -x $f | grep Modify | awk '{ print $3 }'`
- day=`stat -x $f | grep Modify | awk '{ print $4 }'`
- year=`stat -x $f | grep Modify | awk '{ print $6 }'`
- #Convert date string to number string ('Jul 13' to '0713')
- dateFolder=`date -j -f "%b %d" "$month $day" "+%m%d"`
- newFolder=$PIC_ROOT/$year/$dateFolder
- # Make the directory if it doesn't already exist
- mkdir -p $newFolder
- mv -v $f $FILE_ROOT/$year/$dateFolder/
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement