Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/bin/bash
  2. # Organizes files based on their Modify date.
  3. # folder structure is YYYY/MMDD/filename
  4.  
  5. FILE_ROOT=/path/to/files
  6. FILES=$FILE_ROOT/*
  7.  
  8. for f in $FILES
  9. do
  10. # Skip if this is a directory or an executable (Assumes the script is in the same folder)
  11. if ! test -d "$f" && ! test -x "$f"; then
  12. month=`stat -x $f | grep Modify | awk '{ print $3 }'`
  13. day=`stat -x $f | grep Modify | awk '{ print $4 }'`
  14. year=`stat -x $f | grep Modify | awk '{ print $6 }'`
  15.  
  16. #Convert date string to number string ('Jul 13' to '0713')
  17. dateFolder=`date -j -f "%b %d" "$month $day" "+%m%d"`
  18. newFolder=$PIC_ROOT/$year/$dateFolder
  19.  
  20. # Make the directory if it doesn't already exist
  21. mkdir -p $newFolder
  22.  
  23. mv -v $f $FILE_ROOT/$year/$dateFolder/
  24. fi
  25. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement