View file size and directory size under Linux and the size of files in the directory

Source: Internet
Author: User
Tags readable disk usage

In Linux, you will often see the file size, which is usually used by the command du:

The command is explained in detail below:

[Email protected] logs]$ du--help

Usage: du [options] ... [File] ...

Or: du [options] ...--files0-from=f

Calculate the disk usage for each file, and the directory will take the total amount.


The long option must use parameters that are also required for short options.

-A,--all the disk usage of all files, not just the directory

--apparent-size displays surface dosage, not disk usage, although surface dosage is usually

Smaller, but sometimes it can be because of the "hole" between sparse files, internal broken

Not directly referenced blocks, and other reasons.

-B,--block-size= size block with specified number of bytes

-B,--bytes equals--apparent-size--block-size=1

-C,--total display total information

-D,--dereference-args remove symbolic connections listed on the command line

--files0-from=f the file name that ends with NUL in the computed files F corresponds to the disk space occupied

If the value of F is "-", the file name is read from the standard input

-H equals--dereference-args (-D)

-H,--human-readable display dimensions in a more readable manner (e.g. 1K 234M 2G)

--si is similar to-H, but uses 1000 as the base instead of 1024 when calculating

-K equals--block-size=1k

-L,--count-links if it is a hard connection, calculate its dimensions multiple times

-M equals--block-size=1m

-L,--dereference find out the true destination of any symbolic link indication

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

-0,--null each blank line as 0 bytes instead of line break

-S,--separate-dirs does not include the amount of sub-directories

-S,--summarize only calculates the total amount of each parameter in the command column separately

-X,--one-file-system skips directories on different file systems

-X,--exclude-from= file excludes files that match the pattern described in the specified file

--exclude=pattern exclude files that match the patterns described in pattern

--max-depth=n Show catalog totals (use calculation files with--all)

When n is the specified value, the calculation depth is n;

--max-depth=0 equals--summarize.

--time Displays the last modified time for all files in the directory or subdirectory

--time=word Displays the WORD time, not the modified time:

Atime,access,use,ctime or Status

The--time-style= style displays the time in the specified style (the style interpretation rule is the same as the "date" command):

Full-iso,long-iso,iso,+format

--HELP Display this help message and exit

--version display version information and exit


The values shown are from--block-size, Du_block_size, block_size

And BLOCKSIZE the first available SIZE unit in the environment variable.

Otherwise, the default unit is 1024 bytes (or 512 if Posixly_correct is set).


The SIZE can be an optional integer followed by one of the following units:

KB 1000,k 1024,mb 1000*1000,m 1024*1024, also G, T, P, E, Z, Y.


Please report du's error to [email protected]

GNU coreutils Project Home:

GNU Software general help:

Please report du's translation errors to

To get the complete documentation, run: info coreutils ' du invocation '


According to the above parameters, the most common use is-H and--max-depth-n, the use of the following:

[Email protected] logs]$ du-h php101

4.0K php101

[Email protected] logs]$ du-h php111

4.0K php111

[Email protected] logs]$

If you want to look further, you can use the parameter--max-depth=n

For example, to see the size of the next-level directory (medium file) in each directory under the current directory, at which point n=2

[Email protected] logs]$ du-h--max-depth=2.

4.0K./php

4.0K./php101

5.5M./php102/activity.test.org

8.0K./php102/adminfw.test.org

8.0K./php102/admin.test.org

4.7M./php102/affiliate.test.org

298M./php102/api.pb.test.org

8.0K./php102/bidding.m.test.org

304M./php102/bidding.test.org

372K./php102/ck.test.org

27M./php102/comm-bxgxq

717M./php102/community.test.org

8.0K./php102/co.test.org

1.1M./php102/cost.ibs.test.org


If you want to continue to view the next level of directory, n=3

[Email protected] logs]$ du-h--max-depth=3.

4.0K./php

4.0K./php101

5.5M./php102/activity.test.org/logs

5.5M./php102/activity.test.org

4.0K./php102/adminfw.test.org/logs

8.0K./php102/adminfw.test.org

4.0K./php102/admin.test.org/logs

8.0K./php102/admin.test.org

4.7M./php102/affiliate.test.org/logs

4.7M./php102/affiliate.test.org

298M./php102/api.pb.test.org/logs

298M./php102/api.pb.test.org

4.0K./php102/bidding.m.test.org/logs

8.0K./php102/bidding.m.test.org

304M./php102/bidding.test.org/logs

304M./php102/bidding.test.org

368K./php102/ck.test.org/logs

372K./php102/ck.test.org

27M./php102/comm-bxgxq/logs


Change the value of N to see the size of the directory hierarchy. Then go to the catalogue and use Du-ah./view the size of the file in the current directory

[Email protected] huhoo-api]$ Du-ah.

374M./localhost_access_log.2016-04-27.txt

100K./localhost.2016-04-27.log

81M./catalina_112.out.2016-04-28

383M./localhost_access_log.2016-04-28.txt

96K./localhost.2016-04-28.log

26M./catalina_112.out.2016-04-29

174M./localhost_access_log.2016-04-29.txt

44K./localhost.2016-04-29.log

74M./catalina_112.out.2016-04-27

1.5M./localhost_access_log.2016-04-20.txt

140K./localhost.2016-04-20.log

79M./localhost_access_log.2016-04-21.txt

3.1M./localhost.2016-04-21.log

16K./catalina.2016-04-21.log

0./manager.2016-04-21.log

0./host-manager.2016-04-21.log

17M./catalina_112.out.2016-04-21

64M./catalina_112.out.2016-04-22

250M./localhost_access_log.2016-04-22.txt

100K./localhost.2016-04-22.log

77M./catalina_112.out.2016-04-23

345M./localhost_access_log.2016-04-23.txt

88K./localhost.2016-04-23.log

77M./catalina_112.out.2016-04-24

367M./localhost_access_log.2016-04-24.txt

92K./localhost.2016-04-24.log

82M./catalina_112.out.2016-04-25


The other parameters can be interpreted in turn, and this is only the--max-depth=n, which is often used to find which files occupy disk space at a higher frequency.

This article from "Flat Light is true" blog, please be sure to keep this source http://ucode.blog.51cto.com/10837891/1769003

View file size and directory size under Linux and the size of files in the directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.