Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function usage() {
- echo "USAGE: $0 for check file size with minimize and maximaize file"
- echo " [-l or --location for defind location]"
- echo " [-e or --extension] for defind file extension"
- echo " [-s or --stat] for show minimize and maximaize file"
- echo " [-h or --help]"
- echo "Examples:"
- echo "$0 -l /etc/ -e txt -s"
- echo "$0 --location /etc/ -e txt -s"
- echo "$0 -extension txt --stats"
- echo
- exit 1
- }
- local=`pwd`
- type=$2
- while [ $# -gt 0 ]
- do
- case $1 in
- -h|--help )
- usage
- ;;
- -e|--extension)
- file_count=`ls -l | egrep $type -c`
- file_size=`ls -l | egrep $type | awk 'BEGIN{sum=0}{sum+=$5} END{print sum/1024 " kB"}'`
- echo "Location: $local"
- echo "Sum: $file_size"
- echo "Files: $file_count"
- shift
- shift
- ;;
- -s|--stats)
- file_max=`ls -l | egrep $type | awk 'BEGIN{max=$5}{if (max < $5) {max=$5} } END{print max/1024}'`
- file_min=`ls -l | egrep $type | awk 'BEGIN{min=$5}{if (min > $5) {min=$5} } END{print min/1024}'`
- echo "Largest File : $file_max"
- echo "Smallest File : $file_min"
- shift
- ;;
- *)
- usage
- ;;
- esac
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement