Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to enumerate directories of files larger than the specified size in Linux

Shulou Source: shulou.com Published: 2022-06-01 18:06:23 09月25日 Update

This article mainly shows you the "Linux how to enumerate files larger than the specified size of the directory", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to enumerate the directory of files larger than the specified size in Linux" this article.

In Linux systems, it is often necessary to clean up some large files to expand the free space of the disk. But before you clean up these files, you need to find them, or list all the large files in the Linux directory. This paper takes the awk command as an example.

Business background

The / home/pms directory is a working directory. Now the directory takes up too much hard disk space and needs to be cleaned up. Now you need to enumerate all the subfile directories larger than 200MB in this directory, as well as the space occupied by the subfile directory.

Script implementation

Du-h-- max-depth=10 / home/pms/* | awk'{if ($1 ~ / M /) {split ($1, arr, "M")}; if (($1 ~ / G /) | | ($1 ~ / M / & & arr [1] "200)) {printf"%-10s% s\ n ", $1, $2}'| sort-n-r

Among them

Du-h-max-depth=10 / home/pms/*

The results are as follows

$du-h-max-depth=10 / home/pms/*

0 / home/pms/addressCountMap

12K / home/pms/bigDataEngine/conf

1.7M / home/pms/bigDataEngine/analysis/warning

33M / home/pms/bigDataEngine/analysis/log

...

The following awk statement is used to determine the first parameter, to match the string, and to intercept the character M if it is M

If ($1 ~ / M /) {split ($1, arr, "M")}

The following awk statement is used to determine the first parameter and match the string:

1. M, determine whether the capacity is greater than 200MB, and then directly output parameter 1 and parameter 2.

2. Direct output parameters 1 and 2

If (($1 ~ / G /) | ($1 ~ / M / & & arr [1] "200)) {printf"%-10s% s\ n ", $1, $2}

Output result

$du-h-- max-depth=10 / home/pms/* | awk'{if ($1 ~ / M /) {split ($1, arr, "M")}; if (($1 ~ / G /) | | ($1 ~ / M / & & arr [1] "200)) {printf"%-10s% s\ n ", $1, $2}'| sort-n-r

The above is all the contents of the article "how to list directories with files larger than the specified size in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Directory file parameter size location content character space article output function string result statement learning help business example all command Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Shulou Technology Microsoft vpn