Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


How to calculate available disk space on Linux?

Dave, I know how to check for free disk space on Windows XP, but how do I check for the amount of free disk space available on a machine running Linux (CentOS, Fedora, Red Hat, Ubuntu, etc.)?


Dave's Answer:

Checking disk space on a Windows PC is easy -- just right-click on a drive like the C: drive and pick "Properties". But if you have a dedicated server or a Virtual Private Server (VPS) hosted for you at a hosting company, the chances are that it's running some version of Linux, and that you have to connect to it via a command line interface, looking something like the little black box in the image below. This means that most simple administrative commands, like checking free disk space, can no longer be accomplished with something intuitive like right-clicking; most administrative tasks correspond to a typed command that has to be memorized.

Most dedicated servers and Virtual Private Servers come with plenty of disk space, but if you are running any software that you wrote yourself or that was custom-written for you, a small error in the program could cause disk space to fill up quickly. Another possibility is that a remote user might be connecting to a service running on your machine (for example, browsing your website) and generating a lot of traffic, and the webserver writes a record of each transaction to a log file, and if you're getting an enormous amount of traffic, the log file could grow so large that you could start to run out of disk space.

If you're connected to your server via a command like interface like the following:

linux disk space ssh prompt

then to check disk space, type the "df -h" command:

linux disk space df output

Unfortunately the output is not particularly clear about which of these numbers you need to pay attention to. Look in the "Mounted on" column, and look for a row that has "/" listed in that column (it will usually be the first row of the output). In that row, look for the percentage listed in the "Use%" column. That is the percentage of your disk that is full. (Things get a little more complicated if you have more than one hard disk installed, but in cases like that, the hosting company who installed the extra hard disk should be able to tell you how to check how full it is.)

Many programs running on Linux will fail with mysterious error messages if you have run out of disk space. (Unfortunately it's rare for a program to simply check how much disk space is left, and if not enough is free, output an error saying "Not enough available disk space!" It's far more common for a program to simply fail with a cryptic error.) If everything seemed to be working fine yesterday but a program is giving a strange error today, and nothing else has changed, do "df -h" to check if a lack of disk space is the problem.

Even if disk space is not the problem, if you're posting a message asking for help in a Linux forum because you're running into an error that you've never seen before, run "df -h" just so that you can tell people, "I checked and I have plenty of disk space left" -- just to rule out one more possible cause of the problem :)

Bennett Haselton is a technology and political blogger who also maintains a page about how to bypass the FortiNet/FortiGuard Internet filter.


More Useful Unix and Linux Help Articles:
✔   Copy and Paste from the Mac OS X Command Line?
I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...
✔   Shell script to convert lowercase to title case?
As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...
✔   Can I script renaming files based on an XML data map?
I have a folder full of files which are named with four digits and a file extension e.g. 0312.file and an XML-file describing...
✔   Test for valid numbers in a Bash shell script?
In a different discussion on this site [see Redirecting input in a shell script] a visitor commented that "I was too busy trying...
✔   Review: iSSH for the iPad/iPhone
If you're running an online business like I am, there are times when you need to connect and log in to the server...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  





Categorized: Unix and Linux Help , Windows PC Help   (Article 9258, Written by )
Tagged: calculating disk space, centos, disk space, fedora, linux, red hat, ubuntu
Previous: How can I set a "signature" in MSN Hotmail?
Next: Can I automatically tweet my LinkedIn updates on Twitter?




Reader Comments To Date: 1

Mony said, on March 7, 2010 7:07 AM:

I had been installed ubuntu 9.10 via window 7 that i make new partition 10GB and i installed some programs on it infect my ubuntu warning my disk space nearly full. I don't know why? Please u help me?

Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!

I do have a comment, now that you mention it!











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!
Powered By
Linux Journal: Free Issue!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.