Du Command in Linux with examples

Du Command in Linux with examples

DU stands for disk usage. It is a command that is used to check how much space a particular file or folder is consuming on your system.

The general syntax of the du command is as follows:

du [OPTIONS] [DIRECTORY/FILE]

There are many options du support. We will elaborate on the most frequently used commands.

Suppose there is a file anydesk-6.3.0-1.el8.x86_64.rpm located at /home/karim/ and you want to know the size of it in human-readable format (KB, MB, GB etc). You would run:

du -h /home/karim/anydesk-6.3.0-1.el8.x86_64.rpm

output:

You can also display the size of all folders and files located in some directory. Suppose, you want to know the size of all files and directories of /home/karim/. You would run:

du -h /home/karim/

Output:

Let’s move to the next example. In this example, consider you want to print the size of all files and directories including hidden files. You would invoke du along with -a option as follows:

du -a -h /home/karim/

Output: Below is the partial output.

Suppose you want to print the summary (size) of any directory, you need to use -h option along with du.

du -s -h /home/karim/

Output:

Conclusion

By now, you have a good understanding of du command. If you have any questions, please let us know.