Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the du command under linux

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to understand the du command under linux, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Purpose of the du command

The du (disk usage) command calculates the disk space occupied by a file or directory. When no option is specified, it measures the current working directory and all its subdirectories, displays the fast number of each directory, and finally shows the total number of working directories.

Command format

Du [OPTION]... [FILE]...

-a.-all.

Includes all the files, not just the directory

-apparent-size

Print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due

To holes in ('sparse') files, internal fragmentation, indirect blocks, and the like

-B.-block-size=SIZE use SIZE-byte blocks.

-b,-bytes is calculated in bytes

-k is calculated in kilobytes (KB)

-m is calculated in megabytes (M)

-c,-total last plus a total (system default)

-D.-dereference-args.

Dereference FILEs that are symbolic links

H has the same effect as-- si.

-h,-human-readable outputs file size information in a comparative reading manner (for example, 1K 234m 2G). Note: this option is also valid in many other commands (df, ls).

-si has the same effect as-h, except that it is converted in 1000.

-l,-count-links calculates all file sizes, and for hard-linked files, calculates multiple times.

-L,-dereference displays the source file size of the symbolic link specified in the option.

-P,-no-dereference does not follow any symbolic links (default)

-S,-separate-dirs does not include the size of the subdirectory when calculating the space occupied by the directory.

-s,-summarize only shows the total space occupied by the working directory

-x,-one-file-system is based on the file system at the beginning of the processing, and will be skipped in case of other different file system directories.

-X FILE,-exclude-from=FILE excludes the specified FILE

-exclude=PATTERN excludes files that match the style. Pattern is an ordinary Shell style. Represents any character, and * represents any number of characters.

-max-depth=N

List only directories and files whose depth is less than max-depth-the effect of max-depth=0 is the same as-s

Use case

[weijun.hu@test0-32-227] $pwd

[weijun.hu@test0-32-227] / home/weijun.hu/demo

[weijun.hu@test0-32-227] $ll

Drwxrwxr-x 4 weijun.hu weijun.hu 4096 Apr 21 16:00 auto-conf

Drwxrwxr-x 3 weijun.hu weijun.hu 4096 May 19 16:24 bin

Drwxrwxr-x 3 weijun.hu weijun.hu 4096 Apr 21 15:59 build

-rwxrwxr-x 1 weijun.hu weijun.hu 2202 Apr 21 15:27 build.xml

Drwxrwxr-x 5 weijun.hu weijun.hu 4096 Apr 21 15:59 classes

Drwxrwxr-x 8 weijun.hu weijun.hu 4096 May 19 16:31 conf

Drwxrwxr-x 4 weijun.hu weijun.hu 4096 Apr 21 15:25 htdocs

Drwxrwxr-x 5 weijun.hu weijun.hu 4096 Apr 21 15:23 java

Drwxrwxr-x 3 weijun.hu weijun.hu 4096 Apr 21 16:07 jboss

Drwxrwxr-x 2 weijun.hu weijun.hu 4096 May 18 20:29 jboss-conf

Drwxrwxr-x 4 weijun.hu weijun.hu 4096 Apr 21 15:26 lib

Drwxrwxr-x 3 weijun.hu weijun.hu 4096 May 19 19:27 logs

Drwxrwxr-x 6 weijun.hu weijun.hu 4096 Apr 21 16:45 mail_group

Drwxrwxr-x 3 weijun.hu weijun.hu 4096 Apr 21 15:30 project

Drwxrwxr-x 9 weijun.hu weijun.hu 4096 Apr 21 15:23 sql

Drwxrwxr-x 3 weijun.hu weijun.hu 4096 Apr 21 16:30 synclogs

Drwxrwxr-x 4 weijun.hu weijun.hu 4096 Apr 21 15:27 templates

[weijun.hu@test0-32-227] $du-s

793832.-calculate the amount of space occupied by the current directory without specifying the FILE name.

[weijun.hu@test0-32-227] $du-sh

776m.-calculate the amount of space occupied by the current directory without specifying the FILE name. The-h option makes the output easier to read (compared with the previous example)

[weijun.hu@test0-32-227] $du-- max-depth=1-h (note that there are two-before max)

Output the space used by each subdirectory under the current directory

83M. / java

87M. / build

197M. / jboss

128M. / lib

1.1M. / bin

52K. / synclogs

4.8M. / sql

920K. / conf

52K. / logs

20K. / mail_group

56K. / .svn

144M. / htdocs

56K. / jboss-conf

2.7M. / auto-conf

8.0K. / .mule

23M. / classes

43M. / templates

144K. / project

776M.

Find out large files

When the disk space is exhausted, it is inevitable to clean it up. For example, if the / home directory is too large, you can use the following command to see who it is:

Du-s / home/* | sort-nr

The above is how to understand the du command under linux. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report