1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

How To check free disk space in linux

Discussion in 'Linux and Unix' started by tomherry2, Mar 31, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. tomherry2

    tomherry2 Thread Starter

    Joined:
    Mar 31, 2008
    Messages:
    21
    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:
     
  2. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Note: nawk or gawk is to always be preferred over awk, as awk is known to be somewhat lacking in its implementation, but should work in the example script in the previous message. Also, use the chmod command to make tomherry2's script executable, e.g. chmod +x <scriptname>

    -- Tom
     
  3. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    Would "awk" actually be gawk in disguise on Linux, at this point? Running the command "awk --version" might confirm this.

    Peace...
     
  4. usualsuspect

    usualsuspect

    Joined:
    Jul 29, 2002
    Messages:
    548
  5. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Hi tomdkat,

    Looks like on Ubuntu 7.10 Gutsy Gibbon, both awk and nawk are symbolically linked to mawk. Running awk --version does not work for mawk.

    -- Tom
     
  6. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    Funny you posted this today since I checked out the same thing this morning. :D

    Peace...
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/698835

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice