du
Estimate file space usage, reports the amount of disk space used by the specified files and for each subdirectory.(计算文件或目录所占用的硬盘空间)
SYNTAX
du [options]... [file]...
With no arguments, `du' reports the disk space for the current directory. Normally the disk space is printed in units of 1024 bytes, but this can be overridden
frequently used options
`-a' (utility)
`--all'
Show counts for all files, not just directories.
`-c' (same as -x)
`--total'
Print a grand total of all arguments after all arguments have been
processed. This can be used to find out the total disk usage of a
given set of files or directories.(作用与-x相同)
`-D'
`--dereference-args'
Dereference symbolic links that are command line arguments. Does
not affect other symbolic links. This is helpful for finding out
the disk usage of directories, such as `/usr/tmp', which are often
symbolic links.
`-h' (utility)
`--human-readable'
Append a size letter such as `M' for megabytes to each size.
Powers of 1024 are used, not 1000; `M' stands for 1,048,576 bytes.
Use the `-H' or `--si' option if you prefer powers of 1000.
`-H'
`--si'
Append a size letter such as `M' for megabytes to each size. (SI
is the International System of Units, which defines these letters
as prefixes.) Powers of 1000 are used, not 1024; `M' stands for
1,000,000 bytes. Use the `-h' or `--human-readable' option if you
prefer powers of 1024.(假如你想用单位为1000,而不是1024来计算目录或文件的大小时,就用-H)
`-l'
`--count-links'
Count the size of all files, even if they have appeared already
(as a hard link).(相当于-a)
`-L'(没有多大的用处)
`--dereference'
Dereference symbolic links (show the disk space used by the file
or directory that the link points to instead of the space used by
the link).
`--max-depth=DEPTH' (utility实用)
Show the total for each directory (and file if -all) that is at
most MAX_DEPTH levels down from the root of the hierarchy. The
root is at level 0, so `du --max-depth=0' is equivalent to `du -s'.
`-s' (utility)
`--summarize'
Display only a total for each argument.
`-S'
`--separate-dirs'
Report the size of each directory separately, not including the
sizes of subdirectories.
`-x'
`--one-file-system'
Skip directories that are on different filesystems from the one
that the argument being processed is on.(计算所给目录及其所有的子目录的大小)
`--exclude=PAT'
When recursing, skip subdirectories or files matching PAT. For
example, `du --exclude='*.o'' excludes files whose names end in
`.o'.
`-X FILE'
`--exclude-from=FILE'
Like `--exclude', except take the patterns to exclude from FILE,
one per line. If FILE is `-', take the patterns from standard
input.
example:
计算当前目录及其所有子目录的大小
$du -xh(or -ch)
计算某个目录的总的大小
#du -sh /usr
2.7G /usr
假如目录/tmp1下有5个文件,总的大小为200K,还有一个子目录tmp2,总的大小为300K,现在只想计算目录/tmp1的大小,而不包括子目录tmp2的大小,可用-S
$du -Sh /tmp1
300k /tmp1/tmp2
204K /tmp1
你想计算当前目录下的最大深度为2的所有目录的大小
$du -xh --max-depth=2
你想计算当前目录下的最大深度为5的所有目录的大小,但不包括那些以.doc结尾的文件的大小
$du -xh --max-depth=2 --exclude='*.doc'
|