Linux du Command Most Useful Examples

Filed Under: UNIX/Linux

Sometimes, you may be required to check the available disk space occupied by a given set of files.
The Disk Usage (du) command is a standard Linux command that gives information about the disk space usage. Linux du command utilizes many parameters to retrieve the output in different formats. You can use the command to get the files and directory sizes recursively.

In this article, we will walk you through a few examples to get you started with the du command in Linux.

Linux du command to retrieve disk usage summary of current directory

If you wish to get the summary of the disk space utilization on your current working directory run

# du

OR

du .

Sample output

Linux du Command

To track disk space utilization of another directory say /home/jamie/Documents execute

du /home/jamie/Documents

Sample output

Linux du Path To Directory

Print disk usage summary in human readable format

As seen in the previous example, it’s quite difficult to make out the size of the disk usage. The -h argument prints the output in kilobytes.

Sample output

Linux du -h Option

Display summary of overall disk usage

if you want to print out the summary of the overall disk usage in a particular directory, use the -s option. For instance, to find the overall disk usage in the present working directory, run

$ du -sh

Sample output

du -sh

Display disk usage of all file and folders in a specific directory

As you may have realized, the previous examples only display disk usage of folders.

To view both files and folders, use the -a as shown

$ du -ah /home/jamie/Documents

Sample output

du -ah command

Display total disk usage used in a previous session

If you want to get total disk space used in the previous session, use the -c option as shown:

$ du -ch /home/jamie/Documents

Sample output

du -ch

Display disk usage in a tree format

Find out the disk usage of the directory tree with its subtrees in Kilobyte blocks. Use the –k option to display size in 1024-byte units.

$ du -k /home/jamie/Documents

Sample output

du -k

Display disk usage in Megabytes using the -mh option

The summary of disk usage of a directory and its subdirectories in Megabytes use the –mh option. The –m flag represents blocks in Megabytes and –h stands for human readable format.

$ du -mh /home/jamie/Documents

Sample output

linux du -m option

Display Disk Usage after System Modification

To display disk usage after a modification has taken place on your Linux system, use the --time command

$ du -ah --time /home/jamie/Documents

Sample output
show disk usage after system modification

Exclude the display of certain files

The --exclude flag excludes files that match a particular pattern. The example given below excludes all files with the extension.txt files.
We use the flag –exclude as shown below

$ du -ah --exclude="*.txt" /home/jamie/Documents

Sample output
exclude a file from being displayed by du

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages