Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- USAGE="Usage: ./disku -d <directory> [ -h] [-o | -s] [file ...]"
- hflag=
- oflag=
- sflag=
- DIRECTORY=
- while getopts ":d:hos" Option
- do
- case $Option in
- d )
- DIRECTORY=$OPTARG
- ;;
- h )
- hflag=1
- ;;
- \?)
- echo "Invalid option: -$OPTARG" >&2
- echo $USAGE
- exit 1
- ;;
- o)
- oflag=1
- ;;
- s )
- sflag=1
- ;;
- esac
- done
- #Checking directory is valid
- if [ -z $DIRECTORY ]
- then
- echo 'Require -d flag to be passed with a valid directory'
- echo $USAGE
- exit 1
- fi
- # check oflag. No recurse so maxdepth = 1
- if [ -z "$oflag" ];
- then
- cd $DIRECTORY
- find . -maxdepth 1 -type f -printf '%-10s %p\n' | \
- awk '{ x = $1/512; (x==int(x)?x:int(x)+1); s+=x ;printf("%-10d %s\n",x,$2) } END{printf "%-10d %s\n", s,"."} '
- else
- find . -printf '%-10s %p\n' | awk '{ x = $1/512; printf "%-10d %s\n",(x==int(x)?x:int(x)+1),$2 }'
- fi
Add Comment
Please, Sign In to add comment