Get the App
SLTechnology News&Howtos  ›  Network Security  › 

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

Shulou Source: shulou.com Published: 2022-06-01 01:51:23 10月04日 Update

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.

Tags: Files scripts directories size information content screenshots effects permissions authentication space configuration public numerical quantity users accounts check test login Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei MySQL Shulou Tech Info MariaDB