Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux- calculates the total space occupied by all * .conf configuration files in the / etc/ directory

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report