Previous Table of Contents Next

Module 37


The external du command is used to find out how much disk space is used in a directory structure. By using the du command you can:

*  List the disk space used in blocks by each file.
*  List the disk space used in blocks for each subdirectory.

The du command is somewhat of a counterpart to the df command. The df informs you that you are low on space. The du command tells you which files are using the most disk space.

If you do not provide any options or arguments, du displays the number of blocks contained in each file or subdirectory. All files in all subdirectories are added and displayed as one summary for each directory.

If a file is a link, it is only displayed once.


Following is the general format of the du command.

     du [ -rs ]  [ directory_list ]
     du [ -ars ] [ file_list directory_list ]


The following options may be used to control how du functions.

-a Allows the use of filenames instead of just directory names.
-r Returns a message for files that cannot be read or opened. Usually, du ignores files it cannot read or open. It does not mention them or estimate their size.
-s Summary listing. Displays only the totals for specified directories. If the -a option is used, totals for files are given.
If no options are given, du displays the size of each subdirectory in blocks.

BSD (Berkeley)
The BSD version of du does not support the -r option.


The following arguments may be passed to the du command.

directory_list One or more directories are searched and the size of each file or subdirectory is displayed.
file_list One or more files are read and the file size displayed.
If no arguments are provided, the current directory (.) is used as an argument.


The du command does not display any information about files that it cannot read or open. If you do not specify the -a option, du ignores filenames given in its argument list. If links span across unrelated directories, then the file is counted for each occurrence of a link.


Refer to the df command described in Module 32.


Use the du command to check which directories are using most of your disk space. If you are running low on space and need to remove files, the du command provides a means of locating where the bulk of your file space is being used.

As a user you can search your own directories for large files and subdirectories. The system administrator can use du to locate users that are using large amounts of disk space.

Once you locate the unwanted files, use the rm command to discard the files and recover the file space. You may wish to archive the files with the cpio or tar commands before removing them.


In this activity you use the du command to display the disk space you are currently using. Begin at the shell prompt.

1.  Type du and press Return. Your screen should resemble the following display:
     cj du
     4     ./letters
     2     ./bin
     8     ./db
     28    .
2.  Turn to Module 136 to continue the learning sequence.

Previous Table of Contents Next