Skip to content


How to determine your free disk space in Linux

Linux

Although hard drive space is cheap today and we happily throw in a few hundred gigabytes into a server or a desktop, it’s amazing how often the disk gets full. Here are a few Linux tools to help you see how much of your disk has been eaten up, and what’s eating it up, so that you can do something about it before it gets out of hand.

The first command we’ll look at is the “df” command. It comes bundled with all distributions of Linux. “df” stands for “disk free”. It gives you a reading of the state of all your partitions. It gives you the total disk space, the used space, the space available, and then the percentage of space being used.

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 57G 2.4G 52G 5% /
/dev/sda1 99M 12M 83M 12% /boot
/dev/sda2 15G 1.3G 13G 10% /home

The is the kind of reading you can get from df. In the above example I have used the option “-h” which gives the output in a human-readable format. So, instead of showing me the disk space in bytes it uses megabytes and gigabytes which is easier for us to interpret.

Another command I find a lot of use for is “du”. “du” stands for “disk usage”. It can give you a reading of the amount of space a file or folder is using up. To check the amount of space being consumed by a directory called ‘data’ use the following command:

# du -sh data
104K data/

For the above command I have used the following options – “-s” which stands for “summarize”, and “h”, which makes the output human-readable. You can also use this command to see the details of the files and directories inside a directory. To see the individual and total disk of usage or files and directories inside the “data” directory do the following:

# du -shc data/*
4.0K data/1log_script.sh
64K data/logs_files
4.0K data/generic_script.sh
8.0K data/random_script1.sh
4.0K data/random_script2.sh
4.0K data/random_script3.sh
4.0K data/hello_world.sh
4.0K data/data_backup.log
4.0K data/log_backup.log
100K total

We have added the option “c” to the previously used command. “c” adds total disk usage at the end.

Another tool that I use to checkout what’s on my disk is the “find” command. Using find I like to make a list of all the files over a certain size. Say I wanted to check to see which files in my ‘/home’ partition are larger than 10 MB, here’s what I would use:

# find /home -size +10000k

The command is pretty self-explanatory. You can change the “/home” to the directory you want to scan for files, and the “+10000k” to the size of file you want to filter it by.

Hope you find these useful.

Posted in Linux.

Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

 

You can always opt out of this email subscription at any time.

3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Hamdoon says

    Hellow,
    I’m programmer in developer 6i ,and i have system to develope it but there are some problems.This system designed by developer 6i and required to display hard disk free space for Linux inside text tool. So How can i display it .
    please replay the the solution to my email (hamdon85@yahoo.com)>

    Thanks
    Hamdoon.

  2. imtiaz ali says

    plz tell me how to display free space in linux OS. i will wait.

  3. Shaun says

    imatiaz since you if your system uses gnome go to the panel right click and select add to panel. Then on the menu select what I think is called system info then click it on the panel then go to the first tab.



Some HTML is OK

or, reply to this post via trackback.