Knight Talks Tech

*nix – check disk space

If you’ve tried to use ls -lh to get the size of a directory and it’s content, you’ll have found that it doesn’t give you what you were hoping for.

One method to get the size of a directory, including files, sub-directories and their files is to use du (disk usage).

du -sch

The switches in the above example are:
displays only a total for each argument.
prints a total of all arguments after they have been processed, e.g. the total size used by directories and files.
prints the size in an easily readable format such as 12M and 2GB.
Here we can see the result of using du at the same directory level as the ls example:

You can also get a breakdown of directory sizes by omitting the -s switch:

There are many other switches for du, take a look at man du for a list along with an explanation.
If you have any views on using du or maybe you have an alternative preferred method, please let me know in the comments section below.

Exit mobile version