Advertisement
Guest User

getopts

a guest
May 25th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. cd /home/timefiles/
  4.  
  5. FORCE=false
  6.  
  7. while getopts :f opt ;do
  8. case $opt in
  9. f) FORCE=true;
  10. for file in *
  11. do
  12. month="$(stat -c %y "$file"|cut -d\- -f2)"
  13. day="$(stat -c %y "$file"|cut -d\- -f3|awk '{print $1}')"
  14. mkdir -p ./$month/$day
  15. echo "Moving $file to ./$month/$day..."
  16. mv "$file" "./$month/$day/"
  17. done ;;
  18. *) FORCE=false;
  19. for file in *
  20. do
  21. month="$(stat -c %y "$file"|cut -d\- -f2)"
  22. day="$(stat -c %y "$file"|cut -d\- -f3|awk '{print $1}')"
  23. mkdir -p ./$month/$day
  24. echo "Coping $file to ./$month/$day..."
  25. cp -n "$file" "./$month/$day/"
  26. done ;;
  27. esac
  28. done
  29. shift $(($OPTIND -1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement