← linux commands
Views:
du command
The du command is used to check how much disk space is used by files or directories.
Syntax: du [options] file
Example:
du resume.pdf

Options:
-h
Stands for human readable, prints size unit
Example
du -h resume.pdf

In the above example, we can see it printed the unit of size also i.e. K, which stands for Kilobytes here.
-H
To display particular unit for size
Example
du -H -b resume.pdf
Here, -H is used to display particular size unit and -b is that unit which stands for bytes.

-c
To display total size of multiple files
Example
du -h -c code.png video.mp4

Example: Display size of all files in a folder in sorted order
du -h * | sort -h
Here, we are using -h flag with sort, which stands for human numeric sort and compares human readable number and sorts in ascending order.

To do the same in descending order, we can add a reverse flag i.e. -r
du -h * | sort -h -r
