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 use the du command in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "how to use the du command in Linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the du command in Linux".

The Linux du command also looks at the usage space, but unlike the df command, whether the Linux du command looks at the space used by the file and directory disk, or whether it is different from the df command.

What's the difference between du / bin and du-s / bin?

-s is the summary, which shows the sum of the space occupied by the directory

The difference is that when there is a subdirectory under / bin, the result is the same because / bin has no subdirectory, such as

Du / etc will see a lot of output

Du-s / etc has only one line of output

1. Command format:

Du [options] [File]

2. Command function:

Displays the disk usage space for each file and directory.

3. Command parameters:

-an or-all displays the size of individual files in the directory.

-b or-bytes displays the directory or file size in byte.

-c or-- total displays not only the size of individual directories or files, but also the sum of all directories or files.

-k or-- kilobytes output in KB (1024bytes).

-m or-- megabytes output in MB.

-s or-- summarize displays only the total and lists only the last plus value.

-h or-- human-readable is in the unit of KMagazine GetWord ("G"); to improve the readability of information.

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

The source file size of the symbolic link specified in-L or-- dereference display options.

When-S or-- separate-dirs displays the size of an individual directory, it does not include the size of its subdirectories.

-X or-- exclude-from= is in the specified directory or file.

-- exclude= skips the specified directory or file.

-D or-- dereference-args displays the source file size of the specified symbolic link.

The parameters of-H or-- si are the same as-h, but the conversion unit of K _ ~ ~ M ~ G is 1000.

-l or-- count-links repeatedly calculates hardware-linked files.

4. Use an example:

Example 1: displays the space occupied by a directory or file

Command:

Du

Output:

[root@localhost test] # du

608. / test6

308. / test4

4. / scf/lib

4. / scf/service/deploy/product

4. / scf/service/deploy/info

12. / scf/service/deploy

16. / scf/service

4. / scf/doc

4. / scf/bin

32. / scf

8. / test3

1288.

[root@localhost test] #

Description:

Only the directory size of the subdirectories below the current directory and the total size of the current directory are displayed, and the bottom 1288 is the total size of the current directory

Example 2: displays the space occupied by the specified file

Command:

Du log2012.log

Output:

[root@localhost test] # du log2012.log

300 log2012.log

[root@localhost test] #

Description:

Example 3: view the space occupied by the specified directory

Command:

Du scf

Output:

[root@localhost test] # du scf

4 scf/lib

4 scf/service/deploy/product

4 scf/service/deploy/info

12 scf/service/deploy

16 scf/service

4 scf/doc

4 scf/bin

32 scf

[root@localhost test] #

Description:

Example 4: show the space occupied by multiple files

Command:

Du log30.tar.gz log31.tar.gz

Output:

[root@localhost test] # du log30.tar.gz log31.tar.gz

4 log30.tar.gz

4 log31.tar.gz

[root@localhost test] #

Description:

Example 5: only the size of the sum is displayed

Command:

Du-s

Output:

[root@localhost test] # du-s

1288.

[root@localhost test] # du-s scf

32 scf

[root@localhost test] # cd..

[root@localhost soft] # du-s test

1288 test

[root@localhost soft] #

Description:

Example 6: easy-to-read format display

Command:

Du-h test

Output:

[root@localhost soft] # du-h test

608K test/test6

308K test/test4

4.0K test/scf/lib

4.0K test/scf/service/deploy/product

4.0K test/scf/service/deploy/info

12K test/scf/service/deploy

16K test/scf/service

4.0K test/scf/doc

4.0K test/scf/bin

32K test/scf

8.0K test/test3

1.3M test

[root@localhost soft] #

Description:

Example 7: both files and directories are displayed

Command:

Output:

[root@localhost soft] # du-ah test

4.0K test/log31.tar.gz

4.0K test/test13.tar.gz

0 test/linklog.log

0 test/test6/log2014.log

300K test/test6/linklog.log

0 test/test6/log2015.log

4.0K test/test6/log2013.log

300K test/test6/log2012.log

0 test/test6/log2017.log

0 test/test6/log2016.log

608K test/test6

0 test/log2015.log

0 test/test4/log2014.log

4.0K test/test4/log2013.log

300K test/test4/log2012.log

308K test/test4

4.0K test/scf/lib

4.0K test/scf/service/deploy/product

4.0K test/scf/service/deploy/info

12K test/scf/service/deploy

16K test/scf/service

4.0K test/scf/doc

4.0K test/scf/bin

32K test/scf

4.0K test/log2013.log

300K test/log2012.log

0 test/log2017.log

0 test/log2016.log

4.0K test/log30.tar.gz

4.0K test/log.tar.bz2

4.0K test/log.tar.gz

0 test/test3/log2014.log

4.0K test/test3/log2013.log

8.0K test/test3

4.0K test/scf.tar.gz

1.3M test

[root@localhost soft] #

Description:

Example 8: displays the amount of disk space occupied by several files or directories, and calculates the sum of them

Command:

Du-c log30.tar.gz log31.tar.gz

Output:

[root@localhost test] # du-c log30.tar.gz log31.tar.gz

4 log30.tar.gz

4 log31.tar.gz

8 Total

[root@localhost test] #

Description:

With the-c option added, du not only displays the amount of disk space occupied by each of the two directories, but also sums them up on the last line.

Example 9: sort by space size

Command:

Du | sort-nr | more

Output:

[root@localhost test] # du | sort-nr | more

1288.

608. / test6

308. / test4

32. / scf

16. / scf/service

12. / scf/service/deploy

8. / test3

4. / scf/service/deploy/product

4. / scf/service/deploy/info

4. / scf/lib

4. / scf/doc

4. / scf/bin

[root@localhost test] #

Description:

Example 10: output the space used by each subdirectory under the current directory

Command:

Du-h-max-depth=1

Output:

[root@localhost test] # du-h-max-depth=1

608K. / test6

308K. / test4

32K. / scf

8.0K. / test3

1.3M.

[root@localhost test] #

Description:

Thank you for your reading, the above is the content of "how to use the du command in Linux". After the study of this article, I believe you have a deeper understanding of how to use the du command in Linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Development

Wechat

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

12
Report