Linux- calculates the total space occupied by all * .conf configuration files in the / etc/ directory
Calculate the total space occupied by all * .conf configuration files in the / etc/ directory
1. Create a script called confsize.sh with vi. The screenshot is as follows:
The contents are as follows:
#! / bin/bash
Sizenums=$ (ls-l $(find / etc/-type f-a-name * .conf) | awk'{print $5}')
Total=0
For i in $sizenums
Do
Total=$ (expr $total + $I)
Done
Echo "total size of conf files: $total bytes."
Where:
Ls-l $(find / etc/-type f-a-name * .conf) is used for statistics. Information for conf files
Ls-l $(find / etc/-type f-a-name * .conf) | awk'{print $5} 'lists the corresponding size of each file
two。 Give confsize.sh x permission and execute a script to verify the effect.
Check the number of files in the / opt directory of shell logged in with bash and list the specific values and corresponding user accounts
1. Create a script named shell.sh with vi. The screenshot is as follows:
The contents are as follows:
#! / bin/bash
DIR= "/ opt/"
Users=$ (grep "bash$" / etc/passwd | awk-F:'{print $1}')
For username in $users
Do
Num=$ (find $DIR-user $username | wc-l)
Echo "$username have $num files."
Done
2. Temporarily create some test files in the / opt directory to facilitate verification:
3. Add x permissions to the script shell.sh
4. Execute the script and view the information after execution
Welcome to the official account of Wechat: Xiao Wen study Society.