I decided to start a Linux Tip of the Day for myself as a refresher on some Linux cmds and troubleshooting steps that I use daily. Part of my role is to handle linux escalations and these tips have helped me tremendously to figure out issues.

What is du?

According to the du man page, du is used to estimate file space usage. It’s a standard command that can be applied to directories to find out how much space files/directories are taking. One issue that I often run into when supporting users are full hard drives and the du cmd has helped to figure out which files/folders are the culprits.

Just running the du cmd will provide output of directories recursively. With different options/flags, we’re able to format the data to make it more disgestable.

-s, --summarize

-s shows us the summary of the current directory’s usage. So instead of a potentially really long output of all the directories and their contents drilled down, we can use the -s flag to show a summary of the current directory.

~ $ du -s
12669812	.
 ~ $ du -s *
16	Desktop
429860	Documents

-h, --human-readable

-h shows the size output in human-readable format (in Bytes). When combined with the -s flag, we can get a pretty nice readable format.

 ~ $ du -sh *
16K	Desktop
420M	Documents

By using *, du will show the size of each folder individually as opposed to just the total.

-a, --all

-a will list the sizes of ALL files and directories in a given file path (Not just directories).

test $  du -ha
0	./test/test/test.txt
4.0K	./test/test
8.0K	./test
12K	.

A lot of times, we don’t want all of the results, we just want the top 5 or 10. We can sort the output and get the top 5 directories.

~ $  du -sh * | sort -hr | head -5
4.6G	Downloads
655M	games
420M	Documents
33M	github
14M	Pictures