命令简介
du命令用来查看目录或文件所占用磁盘空间的大小。
du命令语法
du [ -a | -s ] [ -k ] [ -m ] [ -g ][ -l ] [ -r ] [ -x ] [ -H | -L ][ File … ]
命令常用参数
a:
显示全部目录和其次目录下的每个档案所占的磁盘空间
b:
大小用bytes来表示 (默认值为k bytes)
c:
最后再加上总计 (默认值)
s:
只显示各档案大小的总合
x:
只计算同属同一个档案系统的档案
L:
计算所有的档案大小
示例
#du -ak
输出
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AIX中man手册对du的解释:
Purpose
Summarizes disk usage.
Syntax
du [ -a | -s ] [ -k ] [ -m ] [ -g ][ -l ] [ -r ] [ -x ] [ -H | -L ][ File … ]
Description
The du command displays the number of blocks used for files. If the File parameter specified is actually a directory, all
files within the directory are reported on. If no File parameter is provided, the du command uses the files in the current
directory.
If the File parameter is a directory, then the number of blocks reported is the sum of blocks allocated for the files in
the directory and the blocks allocated for the directory itself.
Specifying the -a flag reports the number of blocks in individual files. Whether the -a flag is used or not, individual
files specified by the File parameter are always listed.
Specifying the -s flag reports the total blocks for all specified files or all files in a directory.
The block count includes indirect blocks of each file. Block count is calculated in 512-byte units independent of the
cluster size used by the system. Specifying the -k flag calculates the block count in 1024-byte units. Notes:
1 Files with multiple links are counted and written for only one entry.
2 Block counts are based only on file size; therefore, unallocated blocks are not accounted for in the reported block
counts.
3 If du cannot obtain the file attributes or cannot read directories, it reports an error and the exit status of the
command is affected.
Flags
-a
For each file specified, displays the disk usage of the file. For each directory specified, displays the disk usage of
each individual file within the directory, including all subdirectories. Contrast this flag with the -s flag.
-g
Calculates the block count in GB units rather than the default 512-byte units. The output values for the disk usage
would be in floating point numbers as value of each unit in bytes is significantly high.
-H
If a symbolic link is specified on the command line, the du command shall count the size of the file or file hierarchy
referenced by the link.
-k
Calculates the block count in 1024-byte units rather than the default 512-byte units.
-l
Allocates blocks evenly among the links for files with multiple links. By default, a file with two or more links is
counted only once.
-L
If a symbolic link is specified on the command line or encountered during the traversal of a file hierarchy, the du
command shall count the size of the file or file hierarchy referenced by the link.
-m
Calculates the block count in MB units rather than the default 512-byte units. The output values for the disk usage
would be in floating point numbers as value of each unit in bytes is significantly high.
-r
Reports names of inaccessible files and directories. This is the default.
-s
For each file specified, displays the disk usage of the file. For each directory specified, displays the total disk
usage of all files within the directory, including all subdirectories. Contrast this flag with the -a flag.
-x
When evaluating file sizes, evaluates only those files that reside on the same device as the file or directory
specified by the File parameter. For example, you may specify a directory that contains files on several devices. In
this case, the -x flag displays block sizes for all files that reside on the same device as the directory.
If all or any two of the -k, -m and -g flags are specified, the last one specified takes effect. The output of the disk
usage with the flags -m and -g would be rounded off to the nearest second decimal digit.
Exit Status
This command returns the following exit values:
0
Successful completion.
>0
An error occurred.
Examples
1 To summarize the disk usage of a directory tree and each of its subtrees, enter:
du /home/fran
This displays the number of disk blocks in the /home/fran directory and each of its subdirectories.
2 To summarize the disk usage of a directory tree and each of its subtrees in 1024-byte blocks, enter:
du -k /home/fran
This displays the number of 1024-byte disk blocks in the /home/fran directory and each of its subdirectories.
3 To summarize the disk usage of a directory tree and each of its subtrees in MB blocks, enter:
du -m /home/fran
This displays the number of MB disk blocks rounded off to nearest 2nd decimal digit in the /home/fran directory and
each of its subdirectories.
4 To summarize the disk usage of a directory tree and each of its subtrees in GB blocks, enter:
du -g /home/fran
This displays the number of GB disk blocks rounded off to nearest 2nd decimal digit in the /home/fran directory and
each of its subdirectories.
5 To display the disk usage of each file, enter:
du -a /home/fran
This displays the number of disk blocks contained in each file and subdirectory of the /home/fran directory. The
number beside a directory is the disk usage of that directory tree. The number beside a regular file is the disk usage
of that file alone.
6 To display only the total disk usage of a directory tree, enter:
du -s /home/fran
The -s flag instructs the du command to display only the sum total disk usage of the /home/fran directory and the
files it contains. By default, the du command displays an error message if it cannot read a file or directory.
7 To display the disk usage of the files and file hierarchies referenced by all the symbolic links in addition to the
normal files found during traversal of a the /home/fran directory, type:
du -L /home/fran
8 To report the disk usage of the file or file hierarchy referenced by the symbolic link mylink, type:
du -H mylink
Files
/usr/bin/du
Contains the du command.
Related Information
The df command.
The Directories in Operating system and device management explains working with directories and path names.
The Files in Operating system and device management provides information on working with files.
Sorry, the comment form is closed at this time.
No comments yet.