linux check folder size and file size

1. Query the folder size

1. The simplest way to view it is to use the ls -ll and ls-lh commands. When using ls -ll, the size will be displayed in bytes, while ls-lh will be displayed in KB, MB, etc., so compare Be more intuitive.

2. Use the command du -h –max-depth=1 * to view the size of each file and folder in the current directory.

3. To query the total size of the current directory, you can use du -sh, where s represents the statistical summary, that is, only a total size is output.

4. Similarly, through the command du -h –max-depth=0 *, you can only display the size statistics of direct subdirectory files and folders.

5. If you only want to view the total size of the specified directory, you can use du -sh directory name.

6. You can also specify the display level depth for a specified folder, such as du -h --max-depth=0 user/ and du -h --max-depth=1 user/

2. Query file size

 1. Query files larger than 1G in the server
     find / -type f -size +1G
     find / -type f -size +50M (files larger than 50M)

    2.
         The command to query files and attribute information in the server for files larger than 1G is as follows. While querying files larger than 1G, the creator, size (in b), modification date, and path are displayed. 

          find / -type f -size +1G  -print0 | xargs -0 ls -l

    3. Query and sort large files

         Use du -h here to only display the file size and path. If you need to view detailed information,  du -h change  it ls -l to

         find / -type f -size +1G  -print0 | xargs -0 du -h | sort -nr

Guess you like

Origin blog.csdn.net/weixin_40841731/article/details/130377260