←  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
du-output

Options:

-h Stands for human readable, prints size unit

Example

du -h resume.pdf
du-humanreadable-output

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.

du-custom-unit-output
-c To display total size of multiple files

Example

du -h -c code.png video.mp4
du-total-output

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.

du-sort-output

To do the same in descending order, we can add a reverse flag i.e. -r

du -h * | sort -h -r
du-sort-output