Linux-Handson Problem (DU)
Program: First copy below in any file and name it a.sh , after that give execute permission chmod +x a.sh. Run it like ./a.sh.
Code :
#!/bin/sh
Green='\033[0;32m'
while :
do
echo "${Green}WELCOME TO LINUX KURIOSITY"
echo "${Green}LEARN DU COMMAND IN INTERACTIVE WAY"
echo "${Green}Press 0 to learn about du command"
echo "${Green}Press 1 to learn about -a option"
echo "${Green}Press 2 to learn about -h option"
echo "${Green}Press 3 to learn about -c option"
echo "${Green}Press 4 to learn about -L option"
echo "${Green}Press 5 to learn about -s option"
echo "${Green}Press 6 to learn about --time option"
echo "${Green}Press 7 to learn about -x option"
echo "${Green}Press 8 to exit"
echo "Please enter the option"
read option
case $option in
0)
echo "#########START#######"
echo "Summarize disk usage of each FILE, recursively for directories."
echo "#########END########"
;;
1)
echo "#########START#######"
echo "-a write counts for all files, not just directories"
du -a
echo "#########END########"
;;
2)
echo "########START######"
echo "-h option shows the usuage of all the file systems in human readable format"
du -h
echo "#########END######"
;;
3)
echo "########START#####"
echo "-c option produce a grand total"
du -c
echo "########END#######"
;;
4)
echo "########START####"
echo "-L option dereference all links"
du -L
echo "#########END#####"
;;
5)
echo "#########START####"
echo "-s option display only a total for each argument"
du -s
echo "#########END#####"
;;
6)
echo "#########START###"
echo "--time option is used to show last modification time"
du --time du.sh
echo "#########END#####"
;;
7)
echo "########START####"
echo "-x option is used to ignore some specific file"
du --exclude='*.sh' -a
echo "########END#####"
;;
8)
break
;;
esac
done
Output:
WELCOME TO LINUX KURIOSITY
LEARN DU COMMAND IN INTERACTIVE WAY
Press 0 to learn about du command
Press 1 to learn about -a option
Press 2 to learn about -h option
Press 3 to learn about -c option
Press 4 to learn about -L option
Press 5 to learn about -s option
Press 6 to learn about --time option
Press 7 to learn about -x option
Press 8 to exit
Please enter the option
0
#########START#######
Summarize disk usage of each FILE, recursively for directories.
#########END########
WELCOME TO LINUX KURIOSITY
LEARN DU COMMAND IN INTERACTIVE WAY
Press 0 to learn about du command
Press 1 to learn about -a option
Press 2 to learn about -h option
Press 3 to learn about -c option
Press 4 to learn about -L option
Press 5 to learn about -s option
Press 6 to learn about --time option
Press 7 to learn about -x option
Press 8 to exit
Please enter the option
1
#########START#######
-a write counts for all files, not just directories
4 ./du.sh
4 ./df.sh
0 ./1
12 .
#########END########
WELCOME TO LINUX KURIOSITY
LEARN DU COMMAND IN INTERACTIVE WAY
Press 0 to learn about du command
Press 1 to learn about -a option
Press 2 to learn about -h option
Press 3 to learn about -c option
Press 4 to learn about -L option
Press 5 to learn about -s option
Press 6 to learn about --time option
Press 7 to learn about -x option
Press 8 to exit
Please enter the option
2
########START######
-h option shows the usuage of all the file systems in human readable format
12K .
#########END######
WELCOME TO LINUX KURIOSITY
LEARN DU COMMAND IN INTERACTIVE WAY
Press 0 to learn about du command
Press 1 to learn about -a option
Press 2 to learn about -h option
Press 3 to learn about -c option
Press 4 to learn about -L option
Press 5 to learn about -s option
Press 6 to learn about --time option
Press 7 to learn about -x option
Press 8 to exit
Please enter the option
3
########START#####
-c option produce a grand total
12 .
12 total
########END#######
WELCOME TO LINUX KURIOSITY
LEARN DU COMMAND IN INTERACTIVE WAY
Press 0 to learn about du command
Press 1 to learn about -a option
Press 2 to learn about -h option
Press 3 to learn about -c option
Press 4 to learn about -L option
Press 5 to learn about -s option
Press 6 to learn about --time option
Press 7 to learn about -x option
Press 8 to exit
Please enter the option
4
########START####
-L option dereference all links
12 .
#########END#####
WELCOME TO LINUX KURIOSITY
LEARN DU COMMAND IN INTERACTIVE WAY
Press 0 to learn about du command
Press 1 to learn about -a option
Press 2 to learn about -h option
Press 3 to learn about -c option
Press 4 to learn about -L option
Press 5 to learn about -s option
Press 6 to learn about --time option
Press 7 to learn about -x option
Press 8 to exit
Please enter the option
5
#########START####
-s option display only a total for each argument
12 .
#########END#####
WELCOME TO LINUX KURIOSITY
LEARN DU COMMAND IN INTERACTIVE WAY
Press 0 to learn about du command
Press 1 to learn about -a option
Press 2 to learn about -h option
Press 3 to learn about -c option
Press 4 to learn about -L option
Press 5 to learn about -s option
Press 6 to learn about --time option
Press 7 to learn about -x option
Press 8 to exit
Please enter the option
6
#########START###
--time option is used to show last modification time
4 2019-10-12 19:54 du.sh
#########END#####
WELCOME TO LINUX KURIOSITY
LEARN DU COMMAND IN INTERACTIVE WAY
Press 0 to learn about du command
Press 1 to learn about -a option
Press 2 to learn about -h option
Press 3 to learn about -c option
Press 4 to learn about -L option
Press 5 to learn about -s option
Press 6 to learn about --time option
Press 7 to learn about -x option
Press 8 to exit
Please enter the option
7
########START####
-x option is used to ignore some specific file
0 ./1
4 .
########END#####
WELCOME TO LINUX KURIOSITY
LEARN DU COMMAND IN INTERACTIVE WAY
Press 0 to learn about du command
Press 1 to learn about -a option
Press 2 to learn about -h option
Press 3 to learn about -c option
Press 4 to learn about -L option
Press 5 to learn about -s option
Press 6 to learn about --time option
Press 7 to learn about -x option
Press 8 to exit
Please enter the option
8
For store please click on below link :
https://payhip.com/linuxkuriosity
For devops audio book please click on below link:
https://payhip.com/b/Mt9p

Comments
Post a Comment