du Command: Tutorial & Examples

Display the size of a file or directory

The du command is a Unix utility that displays the sizes of directories and files in a file system. It stands for "disk usage," and it is used to find out how much space a particular file or directory occupies on a disk.

The du command displays the sizes of directories and files in blocks, which are typically 512 bytes on most systems. By default, it shows the sizes of all subdirectories and files within the specified directory, recursively. You can use the -h option to display sizes in "human-readable" format, which means that sizes are displayed in a more readable format, such as in kilobytes (KB), megabytes (MB), or gigabytes (GB).

For example, to display the sizes of all files and directories in the current directory, you can use the following command:

du

To display the sizes of all files and directories in the current directory in human-readable format, you can use the -h option:

du -h

The du command has many other options that allow you to customize its behavior, such as excluding certain file types, ignoring certain directories, and displaying sizes in a different format. It is a useful tool for finding out how much space a particular file or directory is occupying on a disk.

Except where otherwise noted, content on this site is licensed under a CC BY-SA 4.0 license CC BY SA