Ten Simple Commands to Check Your Disk Space

By | May 19, 2016

Disk Usage

The ‘du’ command in Linux is a standard Unix/Linux command to check the capacity of disk used by files and directories on a machine. There are several parameter options in which the du command can be utilized to get the results in many formats. Additionally, the du command can be used in a recurrent manner.

Below are the ten useful ‘du’ commands with their examples that will help you to calculate the disk space occupied by the files and directories in Linux.

  1. To calculate the disk space summary of a /home/bodhost directory tree along with its sub directories, enter the below command –

The output displays the number of disk blocks in the /home/bodhost directory as well as its sub-directories.

  1. If you want the results in “Human Readable Format”, use “-h” option with “du” command. With this command you will see the sizes in Bytes, Kilobytes, Megabytes , Gigabytes, Terabytes, etc.

  1. For getting the summary of a grand total disk usage size of an directory, the option “-s” can be used as follows –

  1. You can use “-a” flag with “du” command for displaying the files and directories’ usage.

5. If you use “-a” flag with “-h”, you will get the output in a human readable format i.e. Kilobytes, Megabytes, etc.

6. To find the disk usage of a directory tree with its sub-trees in Kilobyte blocks, use the “-k”. Note: the size will be displayed in 1024 bytes units.

7. To get the information about disk usage of directory tree and its sub-trees in Megabytes (MB) only, use the “-mh” as follows. The “-m” flag calculates the blocks in MB units and “-h” stands for human readable format.

8. If you need to calculate the grand total usage of disk space at the last line, use “-c” flag. For example, your directory has required 674MB space then the last two lines of the output will be as below –

  1. If you want to exclude the “.txt” files while calculating the total directory size, use the flag “-exclude” and the output will be seen as below –

  1. Use the flag “-time” for displaying the disk usage based on time modification as below –