Visit Our UNIX and Linux User Community


Total space Determination

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Total space Determination
# 1  
Old 02-17-2009
Total space Determination

Hi experts,


[root@localhost root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda9 3.8G 1.7G 2.0G 46% /
none 369M 0 369M 0% /dev/shm
/dev/hda10 2.0G 33M 1.8G 2% /tmp
/dev/hda12 1.4G 1.2G 260M 82% /usr


I used df -h to determine the file system usage as shown above . i want to know how much of total space is available in OS for later use in Operating system.

OS used is Red hat linux 8.0


Regards,
Balaji
# 2  
Old 02-17-2009
With awk:

Code:
df -h | 
awk 'NR==1{next}
split($4,f,"G")>1{$4=f[1]*1024}
{sub("M","",$4);s+=$4}
END{print "Available: " s "M"}'

Regards
# 3  
Old 02-17-2009
i cannot understand this coding.Could you please explain me briefly on this?

Thanks $ Regards,
William
# 4  
Old 02-17-2009
Quote:
Originally Posted by William1482
i cannot understand this coding.Could you please explain me briefly on this?

Thanks $ Regards,
William
Code:
awk 'NR==1{next}

Skip the 1st line.

Code:
split($4,f,"G")>1{$4=f[1]*1024}

The split function is used to search for a "G" in the 4th field and to separate the last letter from the numeric value. If the last letter of the 4th field is a "G", f[1] holds the value of the available Gigabytes, f[2] holds the "G" and the return code is 2 otherwise the return code is 1.
If the returncode > 1 the value is multiplied with 1024 (to Megabytes) and assigned to the 4th field.

Code:
{sub("M","",$4);s+=$4}

The sub function deletes the "M" from field $4 (if it's available). The next statement adds the value of the 4th field to the variable s.

Code:
END{print "Available: " s "M"}'

After processing the last line, print the sum of available Megabytes.

Regards

Previous Thread | Next Thread
Test Your Knowledge in Computers #922
Difficulty: Easy
Unix time can be extended backwards from the epoch using negative numbers.
True or False?

9 More Discussions You Might Find Interesting

1. Red Hat

Total storage space and Serial number

Hi, Could you please tell me the commands to find Total storage space and Serial number of Linux server. OS -- Red Hat Enterprise Linux Server release 6.6 (Santiago) This is 2 node cluster. Regards, Maddy (1 Reply)
Discussion started by: Maddy123
1 Replies

2. Solaris

Problem in getting total Disk space using iostat -En command

Hi Everyone, I try to calculate the total hard disk space of a solaris machine using iostat -En command. Iterating the output and summing up all the number present near the Size: will give the exact size of the harddisk. But it is not working for a machine. This command works in many flavors... (2 Replies)
Discussion started by: prasankn
2 Replies

3. Emergency UNIX and Linux Support

Calculating total space in GB for all files with typical pattern

Hi Experts, In a particular dir, I have many files *AJAY*. How can I get total size of all such files. I tried du -hs *AJAY* but it gave me individual size of all files. All I require is summation of all. Thanks, Ajay (4 Replies)
Discussion started by: ajaypatil_am
4 Replies

4. Solaris

command to get the total disk space (available + free)

is there a command to get the total disk space (available + free) on the solaris server ? thanks (3 Replies)
Discussion started by: sudhiroracle
3 Replies

5. Solaris

swap size, total disk space

Hi experts, In my solaris system when i run the command df -h i got the below response.I have some confusion which i want to share with you guys.1)there are two SWAP file system shows are they same or different?2)if i want to count the total disk space should i take both the swap space or only... (2 Replies)
Discussion started by: rafiassam
2 Replies

6. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

7. AIX

used PPs not match the total disk space showed by df

Hi, I see from lsvg the total used PPs is 1050 (67200 megabytes), but when I check the disk space with df command I can only see 31G total space, can somebody tell how this come? Thanks! Victor # lsvg rootvg # lsvg rootvg VOLUME GROUP: rootvg VG IDENTIFIER: ... (2 Replies)
Discussion started by: victorcheung
2 Replies

8. UNIX for Dummies Questions & Answers

df+du=Total space allocated(for a file system)

Hi All, Will df+du=Total space allocted for a file system?? Is the above correct. Please correct me If iam wrong. In one my programs the above is not happening. Please help me out. Many thanks. Regards, Manas (2 Replies)
Discussion started by: manas6
2 Replies

9. UNIX for Dummies Questions & Answers

Hardware Determination

Does anyone know an equiv of lscfg -vp for HP-UX? (2 Replies)
Discussion started by: sam_pointer
2 Replies

Featured Tech Videos