#/bin/bash#check if user input argumentif [ $# -eq 0 ]; then#if no argument print next messge and exit from script
echo “Usage: $0” exit 1fi
# Save first arguments to variables
CheckedDir=”$1″
#
HeadValue=$2
#set value for variable count value 1
count=1#just print empty line
echo “”#Print next message:
echo “Here is the ${HeadValue} biggest directories located in ${CheckedDir}:”echo “”#Getting list of directories and space they use.
du -a –max-depth=1 –one-file-system ${CheckedDir}/ |#next we sort result
sort -rn |sed “1d” |# next we get only first X directories
head -“${HeadValue}” |#next print result to user
while read size dirrr ; do
#counting size in Mbsize=”$(( size / 1024 ))”#show output for user
echo “N°${count} : ${dirrr} is ${size} Mb”((count++))doneecho “”
Script Output
./top5dir.sh /home/yevhen/Here is the biggest directories located in /home/yevhen/:N°1 : /home/yevhen//Fly is 14043 MbN°2 : /home/yevhen//VirtualBox VMs is 5837 MbN°3 : /home/yevhen//Downloads is 2224 MbN°4 : /home/yevhen//.icedove is 963 MbN°5 : /home/yevhen//Downloads is 645 MbN°6 : /home/yevhen//.wine is 602 MbN°7 : /home/yevhen//.cache is 324 MbN°8 : /home/yevhen//Dropbox is 324 MbN°9 : /home/yevhen//.config is 263 MbN°10 : /home/yevhen//.local is 153 Mb
No comments:
Post a Comment