du Command

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 that are used for files. If the File parameter specified is 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 that are reported is the sum of blocks that are allocated for the files in the directory and the blocks that are allocated for the directory itself.

If the object of the du command is a file or directory that exists inside a JFS2 snapshot, the du command gives information for the point-in-time object when the snapshot is created. This information does not include how much space is recovered if the snapshot itself is deleted.

Specifying the -a flag reports the number of blocks in individual files. Whether the -a flag is used or not, individual files that are 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 capacity that is 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 capacity. Therefore, deallocated 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

Table 1. Flags
Item Description
-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 are in floating point numbers as value of each unit in bytes is high.
-H If a symbolic link is specified on the command line, the du command counts the capacity of the file or file hierarchy that is 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 counts the capacity of the file or file hierarchy that is 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 are in floating point numbers as the value of each unit in bytes is high.
-r Reports names of inaccessible files and directories. This flag is the default option.
-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 you evaluate file capacities, evaluates only those files that reside on the same device as the file or directory that is specified by the File parameter. For example, you might specify a directory that contains files on several devices. In this case, the -x flag displays block capacities for all files that reside on the same device as the directory.
Notes:
  1. 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 is rounded off to the nearest second decimal digit.
  2. If both the mutually exclusive options -H and -L are specified simultaneously, the command does not report an error. The last specified option determines the behavior of the utility.

Exit status

This command returns the following exit values:

Table 2. Exit status
Item Description
0 Successful completion.
>0 An error occurred.

Examples

  1. To summarize the disk usage of a directory tree and each of its subtrees, enter the following command:
    du /powervchome/

    This command 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 the following command:
    du -k /powervchome/

    This command 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 the following command:
    du -m /powervchome/

    This command displays the number of MB disk blocks that are 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 the following command:
    du -g /powervchome/

    This command displays the number of GB disk blocks that are 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 the following command:
    du  -a /powervchome/

    This command displays the number of disk blocks that are contained in each file and subdirectory of the /home/fran directory. The number next to a directory is the disk usage of that directory tree. The number next to a regular file is the disk usage of that file alone.

  6. To display only the total disk usage of a directory tree, enter the following command:
    du  -s /powervchome/

    The -s flag instructs the du command to display only the 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 the /home/fran directory, enter the following command:
    du -L /powervchome/
  8. To report the disk usage of the file or file hierarchy that is referenced by the symbolic link mylink, enter the following command:
    du -H mylink

Files

Table 3. Files
Item Description
/usr/bin/du Contains the du command.