Advertisement
Nirvash1997

x10v2

Feb 28th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function usage() {
  4. echo "USAGE: $0 for check file size with minimize and maximaize file"
  5. echo " [-l or --location for defind location]"
  6. echo " [-e or --extension] for defind file extension"
  7. echo " [-s or --stat] for show minimize and maximaize file"
  8. echo " [-h or --help]"
  9. echo "Examples:"
  10. echo "$0 -l /etc/ -e txt -s"
  11. echo "$0 --location /etc/ -e txt -s"
  12. echo "$0 -extension txt --stats"
  13. echo
  14. exit 1
  15. }
  16. local=`pwd`
  17. type=$2
  18. while [ $# -gt 0 ]
  19. do
  20. case $1 in
  21.  
  22. -h|--help )
  23. usage
  24. ;;
  25. -e|--extension)
  26. file_count=`ls -l | egrep $type -c`
  27. file_size=`ls -l | egrep $type | awk 'BEGIN{sum=0}{sum+=$5} END{print sum/1024 " kB"}'`
  28. echo "Location: $local"
  29. echo "Sum: $file_size"
  30. echo "Files: $file_count"
  31. shift
  32. shift
  33. ;;
  34. -s|--stats)
  35. file_max=`ls -l | egrep $type | awk 'BEGIN{max=$5}{if (max < $5) {max=$5} } END{print max/1024}'`
  36. file_min=`ls -l | egrep $type | awk 'BEGIN{min=$5}{if (min > $5) {min=$5} } END{print min/1024}'`
  37. echo "Largest File : $file_max"
  38. echo "Smallest File : $file_min"
  39. shift
  40. ;;
  41. *)
  42. usage
  43. ;;
  44. esac
  45.  
  46. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement