In Linux, the full name of du is "Disk Usage". It is a command to count the disk space occupied by a directory or file. The syntax is "du [option] [directory or file name]". The du command supports a variety of options: 1. "-h", which can display the size in easy-to-read units; 2. "-s", which can display the total size of the directory; 3. "-d", etc.
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
linux du command
du is the abbreviation of Disk Usage, one of the most popular commands on Linux, du is the statistical directory or file Commands that occupy disk space
du The format of the command is as follows:
du [选项] [目录或文件名]
Commonly used options are as follows:
- a: Display the size of all files and folders in the directory
-h: Display the size in easy-to-read units such as Kb, Mb, Gb, etc.
--si: Similar to the -h option, but the calculation is based on 1000 instead of 1024
-s: Display the total size of the directory
-d: is the abbreviation of the --max-depth=N option, indicating which level of directories to go deep into. Directories exceeding the specified number of levels will be ignored
-c: In addition to displaying the directory size In addition, an extra line displays the total usage
--time: Displays the time of the most recently modified files in each directory
-t: Yes --threshold=Abbreviation for SIZE, filters out files and directories smaller than SIZE
--exclude=PATTERN: Filters out file names or directory names that match PATTERN
Usage example
Display all directories and file sizes
The following example shows The size of all directories and files under the directory, the default unit is Kb
[root@ecs-centos-7 tt]# du -a temp/ 4 temp/suba.txt 4 temp/test/abc.txt 4 temp/test/ha/ha.txt 8 temp/test/ha 16 temp/test 4 temp/time.txt 28 temp/
Note: If the above example does not use the -a option, by default only the directory size will be displayed, not the file size. That is, executing du temp/
will only display the directory size. Please see the following example:
[root@ecs-centos-7 tt]# du temp 8 temp/test/ha 16 temp/test 28 temp
Displayed in an easy-to-read manner
Default display The size only has a single number, not even a unit, which makes people look a little confused at first glance. The -h option can be used to display the size in a human-readable way. This option should be the most commonly used
[root@ecs-centos-7 tt]# du -b temp/ 4117 temp/test/ha 8218 temp/test 12326 temp/ [root@ecs-centos-7 tt]# du -h temp/ 8.0K temp/test/ha 16K temp/test 28K temp/ [root@ecs-centos-7 tt]# du --si temp/ 8.2k temp/test/ha 17k temp/test 29k temp/
In the above example, the default calculation base of the -h option is 1024, and the default calculation base of the --si option is 1000
So temp/test/ha
The size of the directory calculated with the -h option is 8.0K, and the size calculated with the --si option is 8.2K
-h and the size unit of the --si option are automatically adjusted with the size of the directory and file
Total directory size
Sometimes we only need to know the total size of a directory and do not need to know the size of subdirectories and files in subdirectories. We can obtain the total directory size through the -s option
[root@ecs-centos-7 tt]# du -sh . 72K . [root@ecs-centos-7 tt]# du -sh temp/ 28K temp/
The above example obtains the total size of the current directory and the total size of the temp/ directory respectively
The total size of the directory can also be obtained through the -c option, but it displays the subdirectory size first, and the last line displays the total size. The last line of the example below total
The 28K in front of the string indicates the total size of the temp/ directory
[root@ecs-centos-7 tt]# du -ch temp/ 8.0K temp/test/ha 16K temp/test 28K temp/ 28K total
Specify the directory depth
If there are many in one directory Subdirectory, if you only want to display the size of the directory with a specified number of levels, you can use the -d option to achieve the subdirectory structure of
temp/ as follows:
[root@ecs-centos-7 tt]# tree -d temp/ temp/ └── test └── ha 2 directories
Specify the directory depth
[root@ecs-centos-7 tt]# du -d 0 temp/ 28 temp/ [root@ecs-centos-7 tt]# du -d 1 temp/ 16 temp/test 28 temp/ [root@ecs-centos-7 tt]# du --max-depth=2 temp/ 8 temp/test/ha 16 temp/test 28 temp/
du -d 0 temp/
: Displays the 0th level directory, which is the total size of the current directory. This is equivalent to the -s option
du -d 1 temp/
: Display the total size of the first-level directory, that is, the temp/test directory
du --max-depth=2 temp/
: Display the second-level directory, that is, temp/ The total size of the test/ha directory
Display the latest modification time
[root@ecs-centos-7 tt]# du --time temp 8 2020-07-21 20:11 temp/test/ha 16 2020-07-21 20:11 temp/test 28 2020-07-21 20:13 temp
The above example displays the latest modification time of each directory, and the time granularity is only accurate to the minute
If you want to display a finer granularity, you can use the --time-syle=STYLE option to specify the output format of the time, where STYLE represents the formatted output string of the date, and date
The format of the formatted output of the command is the same
Example 1: Display the number of seconds in UTC time (the number of seconds from January 1, 1970 to the present)
[root@ecs-centos-7 tt]# du --time --time-style="+%s" temp/ 8 1595333498 temp/test/ha 16 1595333514 temp/test 28 1595333582 temp/
Example 2: Display the complete Year, month, day, hour, minute and second
[root@ecs-centos-7 tt]# du --time --time-style="+%F %T" temp/ 8 2020-07-21 20:11:38 temp/test/ha 16 2020-07-21 20:11:54 temp/test 28 2020-07-21 20:13:02 temp/
Filter by size
From the displayed results, filter out the directories and files of the specified size
[root@ecs-centos-7 tt]# du -b temp/ 4117 temp/test/ha 8218 temp/test 12326 temp/ [root@ecs-centos-7 tt]# du -b -t 4118 temp/ 8218 temp/test 12326 temp/
above In the example, directories smaller than 4118 bytes are filtered out
Filter by directory name or file name
If there are too many subdirectories in one directory, we can filter based on the subdirectory name Or the file name matches the specified pattern string, thereby filtering out the matching directories and files
[root@ecs-centos-7 tt]# du -a temp 4 temp/suba.txt 4 temp/test/abc.txt 4 temp/test/ha/ha.txt 8 temp/test/ha 16 temp/test 4 temp/time.txt 28 temp [root@ecs-centos-7 tt]# du -a --exclude=*a* temp/ 4 temp/test 4 temp/time.txt 12 temp/
In the above example, the filtered pattern string is: *a*
It means to filter out directories or files whose directory names or file names contain the characters a
. In the example, the directory or file names in the first four lines all contain the characters a
, so they are all filtered. Lost
What are the files that fill up the disk
The problem that developers often encounter is that the disk is full. At this time, we can use du and sort in combination. Find the "culprit"
- 当前目录下文件从大到小排序
[root@ecs-centos-7 tt]# du -sh temp/* | sort -hr 10M temp/clpay.tar 16K temp/test 4.0K temp/time.txt 4.0K temp/lnsuba
- 当前目录以及子目录从大到小排序
[root@ecs-centos-7 tt]# du -ah temp/* | sort -hr 10M temp/clpay.tar 16K temp/test 8.0K temp/test/ha 4.0K temp/time.txt 4.0K temp/test/ha/ha.txt 4.0K temp/test/abc.txt 4.0K temp/lnsuba
- 磁盘占用最大的三个目录以及子目录
[root@ecs-centos-7 tt]# du -ah temp/* | sort -hr | head -n 3 10M temp/clpay.tar 16K temp/test 8.0K temp/test/ha
相关推荐:《Linux视频教程》
The above is the detailed content of what is linux du. For more information, please follow other related articles on the PHP Chinese website!

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

在linux中,交叉编译是指在一个平台上生成另一个平台上的可执行代码,即编译源代码的平台和执行源代码编译后程序的平台是两个不同的平台。使用交叉编译的原因:1、目标系统没有能力在其上进行本地编译;2、有能力进行源代码编译的平台与目标平台不同。

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
