this will be another quick and dirty post. In this article I am going to demonstrate how to use the commands “df” and “du” to display disk information on usage and such.
As usual I expect that you already have a running Ubuntu Server system but if you need help check out the Ubuntu Server install article here.
Since in a traditional way Linux Server don’t run with a Desktop Environment due to the resource overhead we will focus on the command line interface. So how can you display disk usage and statistics on the command line? Well this is very simply. Lets break this down to two parts. In the first part I show a few examples for the command “df” and in the second part I do the same for the command “du”.
How to use the command df
“df” is short for “disk free” and it is a nice little tool to present filesystem information to the end user. If you run the command without any command line switches it will return the following to the end user.
It presents you with a table of information but the numbers are not really human friendly. Run the following command:
This looks more like humans could use. You can also display more information with the -a command line switch which show information of all filesystems. Run the following command:
Thats a lot of information but again not very human friendly. You can combine command line switches. Let combine “-a” and “-h” and see what happens. Run the following command:
You can also display the Filesystem type by using the “-T’ command line switch. Lets execute the following command:
As you can see it adds another column to it to display the type of the filesystem. There are tons of more command line switches but I find those most useful. If you like to read up more about this command read here.
How to use the command du
“du” stands for “disk usage” and it is a very hand little tool as well. It displays the disk usage information of files and folders and it has lots of command line switches as well. I will show you my most used switches here. First lets execute the command by it self so we can see what it does. You should see something similar to the following:
When you run this command it is going through your entire system and starts displaying all folder disk usage information and you need to hit <ctrl> + c to stop it. The command without command line switch is not that useful. Let’s make it more usable. Lets display disk usage information for a specific folder or path. Execute the following command:
This makes it more usable but it is still quiet overwhelming when you run it against /usr. We will narrow it down further later on. As you can see the numbers are again not very user friendly and as you saw with the previous command we can apply the “-h” command line switch to make it more human friendly. Execute the following command:
du -h /boot
This is much better that way. If this is still too broken down for you we can summarize it. Execute the following command:
du -sh /usr
The /usr folder is quiet large and it contains lots of files and folders so when you execute the command it takes a brief moment but the result is quiet condensed.
If you like to display the file disk usage information you need to use the “-a ” command line switch. I will combine it here with the “-h” switch for human readability. Execute the following command:
du -ah /boot
This is it. I showed you my most used “du” command options. If you like to read up more about the “du” command and its option read here.
This concludes this article demonstrating the “df” and “du” commands. I hope it was a useful read and I would appreciate some feedback or future article suggestions.