Moneycontrol Brokerage Recos

Tuesday, September 20, 2011

Command to check how much hard disk space is free in Linux?

# df -h
The output will be 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 Here the size is represented by megabytes and gigabytes.

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

No comments:

Post a Comment