Check the size of folders and files in Linux system

1. Query the folder size

1. The simplest way to view

ls -ll		// 显示成字节大小
ls -lh		// 以KB、MB等为单位进行显示

2. Check the size of each file and folder in the current directory

du -h –max-depth=1 *

3. Query the total size of the current directory

du -sh

s represents statistical summary, that is, only one sum size is output.

4. Only direct subdirectory files and folder size statistics are displayed.

du -h –max-depth=0 *

5. Only view the total size of the specified directory

du -sh 目录名称

6. Specify the display level depth for the specified folder

du -h --max-depth=0 user/
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 (大于50M的文件)

2. Query files and attribute information larger than 1G in the server

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

While querying files larger than 1G, the creator, size (in b), modification date, and path are displayed.

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, change du -h to ls -l.

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

3. du command and syntax

du is the abbreviation of Disk Usage. It is one of the most commonly used commands on Linux. It is used to estimate the disk space occupied by files or directories. It is also a very basic command. Anyone who uses Linux should master its usage.

Usage: du [OPTION]... [FILE]...
       du [OPTION]... --files0-from=F

Commonly used [OPTION] options are as follows:

-a: 显示目录中所有文件以及文件夹大小

-h: 以 Kb、Mb 、Gb 等易读的单位显示大小

--si: 类似 -h 选项,但是计算是用 1000 为基数而不是1024

-s: 显示目录总大小

-d: 是 --max-depth=N 选项的简写,表示深入到第几层目录,超过指定层数目录则忽略

-c: 除了显示目录大小外,额外一行显示总占用量

--time: 显示每一个目录下最近修改文件的时间

-t: 是 --threshold=SIZE 的简写,过滤掉小于 SIZE 大小的文件以及目录

--exclude=PATTERN:过滤与 PATTERN 匹配的文件名或者目录名

Guess you like

Origin blog.csdn.net/weixin_44816664/article/details/132863662