Submit your breaking news stories and original articles to us by contacting us
There are plenty of tools with which you can check your disk space. However, Linux already has a built in function to show you just what you need to know. Open a terminal window or push (ctrl+alt+F1 to go to console) and type:
# df
You will see something like this(your output may be different, depending on how many partitions/harddrives/cdroms you have mounted):
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda3 78012484 17606992 56442660 24% /
/dev/hda1 101086 16400 79467 18% /boot
none 516808 0 516808 0% /dev/shm
/tmp 247919 7339 227780 4% /tmp
This one looks a bit unreadable, because size is represented in 1K-blocks, lets try to make it clean and more readable:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda3 75G 17G 54G 24% /
/dev/hda1 99M 17M 78M 18% /boot
none 505M 0 505M 0% /dev/shm
/tmp 243M 7.2M 223M 4% /tmp
Now the size is represented by megabytes and gigabytes … better? :) Now let’s create an executable file to show the disk sizes:
#!/bin/sh
DISC=$1
PARTITION=`df -h |grep $DISC |awk ‘{print $1}’`
SIZE=`df -h|grep $DISC|awk ‘{print $2}’`
USED=`df -h|grep $DISC|awk ‘{print $3}’`
FREE=`df -h|grep $DISC|awk ‘{print $4}’`echo “Partition: $PARTITION”
echo “Total size: $SIZE”
echo “Used space: $USED”
echo “Free space: $FREE”
Simply copy & paste this script into for example into a file named info.sh(create it with VI or JOE or even PICO). Next, you’ll need to make it executable. To do this, use the following command:
# chmod +x info.sh
Now, to execute the file, you need to run it, and pass it the correct argument. For our example, we are going to use hda3. So, to execute the file, type in the command as below….
# ./info.sh hda3
Tadaaa :)
Linux Running Out of Space?
Convert a Windows System to Dual-Boot Linux
Warner Patents Hybrid DVD/HD DVD/Blu-ray Disc
Supermount: Linux Automounting
Windows 95 and Linux on the PSP
Forever Geek is a resource for all things geek. You can stay tuned by having the latest FG news delivered to you for free via RSS.

Netbooks and User Satisfaction: It’s All About Expectations
10 Cool Sony Walkman photos – celebrate Walkman’s 30th birthday
22 Responses for "Check Disk Space in Linux"
October 6th, 2005 at 2:27 pm
1I can see this being useful if you’re not running a GUI. But if you are, most modern distros come with apps that does the same thing. For example, SUSE 9.2 came with this
October 9th, 2005 at 11:25 pm
2GUI, schmooey. I access tons of Web, DB and other server type remotely that are running various flavors of Linux and BSD. An admin always wants to know things like free disk space and what apps or logs are hogging the space if the host starts to freak out.
January 14th, 2006 at 5:47 pm
3Nice, it doesn’t so important to me, but nice idea!
March 6th, 2006 at 12:18 pm
4You are greatest. Job well done. I think that U helped many how are beginers in linux as myself.
March 16th, 2006 at 4:34 pm
5If you have only two pennies left in the world, with the first penny, you should buy rice to feed your family. With the second penny, say the wise Japanese, you should buy a lily. The Japanese understand the importance of dreaming…
March 30th, 2006 at 4:09 am
6casino gambling Keyword doesn’t matter
April 28th, 2006 at 6:02 pm
7That script is pretty lame. It just lays it out in a different format. Big deal.
May 13th, 2006 at 4:02 am
8This is very interesting site…
June 27th, 2006 at 1:03 pm
9proverka2007
September 26th, 2006 at 3:03 pm
10Just thought I would add this as we have a ton of servers that we only touch if we need to. If your server can email you can add this to the bottom and comment out the echo’s. I have it emailing my cell phone.
if [ "$FREE" -le "$MINSPACE" ]; then
mail -s “Running out of room on $DISC” cell@phone.com Just thought I would add this as we have a ton of servers that we only touch if we need to. If your server can email you can add this to the bottom and comment out the echo’s. I have it emailing my cell phone.
if [ "$FREE" -le "$MINSPACE" ]; then
mail -s “Running out of room on $DISC” cell@phone.com < sendtext
fi
Where sendtext is just a file with “Running out of space” in it.
November 27th, 2006 at 7:11 pm
11Thank you for posting this, it helped me finding out how much I had left. IÂŽm a starting Linux user and this is very helpful.
December 18th, 2006 at 7:35 am
12Very well! Your site is neat!
[url=][/url]
December 24th, 2006 at 10:02 am
13good info. thank you
df –si :P
February 27th, 2007 at 1:43 pm
14I found this page because gparted doesn’t recognize the partitions on my USB hard drive. df works great. thanks
March 18th, 2007 at 1:42 pm
1510x… for df.
if i want to see size for individual folder ?
June 28th, 2008 at 1:10 pm
16For a folder, use du. Here’s the nitty-gritty (man du for everything):
-h print sizes in human readable format (e.g., 1K 234M 2G)
-s display only a total for each argument
-a write counts for all files, not just directories
What this means is with the -s option, it only shows you stats for what you’re concerned with, otherwise it operates recursively and shows you stats for all the subdirectories of what you enter (by default it doesn’t list files without the -a switch).
Examples:
$ du -h -s /home/george
107M /home/george
$ du -h /home/george
7.2M /home/george/openldap-2.3.39/tests
7.1M /home/george/openldap-2.3.39/clients
6.1M /home/george/openldap-2.3.39/doc
98M /home/george/openldap-2.3.39
107M /home/george
July 31st, 2008 at 9:43 pm
17thank you so much. Very helpfull information.
October 9th, 2008 at 1:56 am
18Fine!. The above post was very helpful for me. Thanks for posting it here…
November 20th, 2008 at 10:36 am
19The script (above) does Not work for me? I am running Ubuntu 8.04, i get errors in grep, awk and the rest of the commands saying like you have to use a switch with grep etc.??
February 3rd, 2009 at 10:55 am
20Hello;
How can I tell which partition has how much space AND How can I Move files from a full partition to ones with more space?
Thanks!
df , du -h and fdisk -l are useful But do not tell me what I need to know.
I am not sure since I inherited these servers and didnt set up partitions?:
for instance;
root@myserver:/# df -h
Filesystem Size Used Avail Use% Mounted on
varrun 941M 64K 941M 1% /var/run
varlock 941M 0 941M 0% /var/lock
procbususb 941M 104K 941M 1% /proc/bus/usb
udev 941M 104K 941M 1% /dev
devshm 941M 0 941M 0% /dev/shm
but when I do an fdisk -l I get;
root@myserver:/# fdisk -l
Disk /dev/sda: 123.5 GB, 123522416640 bytes
255 heads, 63 sectors/track, 15017 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 15017 120624021 83 Linux
Disk /dev/sdb: 82.3 GB, 82348277760 bytes
255 heads, 63 sectors/track, 10011 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 10011 80413326 83 Linux
Disk /dev/sdc: 250.0 GB, 250058301440 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 2432 19535008+ 83 Linux
/dev/sdc2 2433 2554 979965 82 Linux swap / Solaris
/dev/sdc3 2555 30401 223681027+ 8e Linux LVM
SO…. HOW DO I MOVE FILES FROM like sda1 to sdc1 ?etc…
Thank You!
June 23rd, 2009 at 3:16 am
21I want to check free space (Unalloacted Partition) in linux without calculating.
want to check throgh command line.
Means alternate command for “hwbrowser”
September 4th, 2009 at 8:00 pm
22I want to say, ctrl+ alt + F1 leads to shutdown my KDE unnormally but not open a terminal. :-)
Anyway, Thanks very much! this blog entity is useful to me.
RSS feed for comments on this post
Leave a reply