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.
Table of Contents
- 1 Linux du command to retrieve disk usage summary of current directory
- 2 Print disk usage summary in human readable format
- 3 Display summary of overall disk usage
- 4 Display disk usage of all file and folders in a specific directory
- 5 Display total disk usage used in a previous session
- 6 Display disk usage in a tree format
- 7 Display disk usage in Megabytes using the -mh option
- 8 Display Disk Usage after System Modification
- 9 Exclude the display of certain files
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
To track disk space utilization of another directory say
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.
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
Copy$ 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
Copy$ du -ah /home/jamie/Documents
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:
Copy$ du -ch /home/jamie/Documents
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.
Copy$ du -k /home/jamie/Documents
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.
Copy$ du -mh /home/jamie/Documents
Display Disk Usage after System Modification
To display disk usage after a modification has taken place on your Linux system, use the
Copy$ du -ah --time /home/jamie/Documents
Exclude the display of certain files
--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
Copy$ du -ah --exclude="*.txt" /home/jamie/Documents