Random Linux

Linux, video games and web hosting

Using the du command will give you a list of the directories that are in your current directory, as well as the total size of all of the files and subdirectories included in that directory. I personally prefer to use the following, which will show the sizes in an easier to read format. It will show the files in GB or MB as well as KB, instead of all KB, which is what you will get with just du alone.

du -h

To show the size of a particular directory, you can specify that at the end of the command. It will output the size of the directories and subdirectories that are in that folder. The following will show the directories and subdirectories in the public_html folder and all of it’s subdirectories, in human readable format. The last value will be the total size.

du -h /home/user/public_html

You can also list the files as well as the directories by adding the -a flag. This will make it list all files and directories in the current directory and subdirectories, as well as their sizes in human readable format.

du -ah

If you are not concerned with the individual file sizes and only the total size of the directory as a whole, you are able to use the -s flag to get a total size. I add the h flag in as well to make it easier to read

du -sh

Lastly, the way that I use du the most personally is by adding on a –max-depth value. This will specify the number or directories deep to go. So, using a value of 1 will only show the sizes of the directories that are in the current directory without going further into them. Using a value of 2 will show the directories that are in the current directory and the ones inside that.

du -h –max-depth=1

There are many, many more ways to use the du command, but these are the ones that I find myself using the most. How do you use the du command? Leave us a comment and share your knowledge as well!

March 17th, 2011

Posted In: General

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *