Get free space of file system


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get free space of file system
# 1  
Old 06-08-2010
Get free space of file system

Hi guys,

I'm trying to get free space in GB of file system into parameter.
I have the following code:
Code:
> cat get_free_space_FS.ksh
#! /bin/ksh

FS=/dw/mar
FreeSpace=`df -h | grep $FS | awk '{print $4}'`
echo $FreeSpace

> ./get_free_space_FS.ksh
362G

My question is ,how can I cut in the "df -h" command the "G" sign from the output , because I want to do manipulations on a numeric result?

Thanks in advance,
Nir
# 2  
Old 06-08-2010
Hi.

Try changing this:

Code:
FreeSpace=`df -h | grep $FS | awk '{print $4}'`

To this:
Code:
FreeSpace=`df -h | grep $FS | awk '{print $4 + 0}'`

# 3  
Old 06-08-2010
one way, using similar to what you have, and different FS for purposes of example:

Code:
#  df -h /tmp
Filesystem             size   used  avail capacity  Mounted on
swap                    78G   670M    77G     1%    /tmp

so,


#  df -h /tmp |awk 'NR==2{print substr($4,1,length($4)-1)}'
77

using grep has potential to hit multiple matches, so df the FS directly...

HTH

---------- Post updated at 11:11 AM ---------- Previous update was at 11:08 AM ----------

Quote:
Originally Posted by scottn
Hi.

Try changing this:

Code:
FreeSpace=`df -h | grep $FS | awk '{print $4}'`

To this:
Code:
FreeSpace=`df -h | grep $FS | awk '{print $4 + 0}'`

This is nice.... caveat - works for nawk, but not (solaris) awk
# 4  
Old 06-08-2010
Code:
df -k | grep $FS | awk '{printf "%d\n",$4/1024/1024}'

Remove a division if you need MiB instead of GiB.

And if you need the free space of a certain mount point you can even shorten it to
Code:
df -k $FS | awk '{printf "%d\n",$4/1024/1024}'

# 5  
Old 06-08-2010
Hi pludi/Tytalus,

Thanks a lot!
very nice solutions.

Best regards,
Nir
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

No space in the file system

A file system has reached 100%. I have tried adding space using chfs -a size=+100 command to that file system. However, the % used is not decreasing from 100%. Is there a way to add more space? Also, can someone suggest a script to send a mail alert when a file system is reaching 90%. G (4 Replies)
Discussion started by: ggayathri
4 Replies

2. HP-UX

Increasing space in file system

Hi Friends, I want to cut space from one file system and add in another file system. For example I have 100 gb space in /oracle/TST/oraarch I wnat to cut 50 gb from this file system and add 50 in /oracle/TST/sapdata1. Please hel, How I can do it. Regards, Bhagawati Pandey (3 Replies)
Discussion started by: BPANDEY
3 Replies

3. Fedora

Need to incrwase PHYSICAL VOLUME space on hard drive with free space on it

Hi, I run Fedora 17. I created a physical volume of 30GB on a disk with 60GB of space so there is 30GB of free space. On the physical volume, I created my volume group and logical volumes. I assigned all the space in the physical volume to my volume group. I need to add the 30GB of free space... (1 Reply)
Discussion started by: mojoman
1 Replies

4. Solaris

No space left on device but free space and inodes are available...

hi guys, me again ;) i recently opened a thread about physical to zone migration. My zone is mounted over a "bigger" LUN (500GB) and step is now to move the old files, from the physical server, to my zone. We are talking about 22mio of files. i used rsync to do that and every time at... (8 Replies)
Discussion started by: beta17
8 Replies

5. 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

6. UNIX for Dummies Questions & Answers

free space, used space in ftp

Is possible to see how much available space there is on a ftp server and how much is used through ftp ? how ? free space: used space: thanks (1 Reply)
Discussion started by: aneuryzma
1 Replies

7. Programming

How to get free disk space size in C/C++ program( Solaris system)

How to get free disk space size in C/C++ program( Solaris system)? Is there any standard function or system function? Just like "df" or "getdfree" in Linux. (4 Replies)
Discussion started by: yidu
4 Replies

8. UNIX for Dummies Questions & Answers

free some space in file system

dear all, I have some problem in my file system : df -k result : ... /dev/md/dsk/d3 3101839 2736380 303423 91% /var ... it occupied around 2.7 gb but when I tried command du -sk /var 813991 /var so /var only have around 800Mb , Do you know why there is many difference... (6 Replies)
Discussion started by: fu4d
6 Replies

9. Solaris

Lost space on file system

Hi everybody, I got a problem on my SUN server in Solaris 9. I'll try to explain, if somebody could help me. I have mounted some volumes in RAID 0+1, that is stripped slices and then mirror. To be clear the result of metastat d80 is as follow : d80: Mirror Submirror 0: d81 State:... (2 Replies)
Discussion started by: aribault
2 Replies

10. UNIX for Dummies Questions & Answers

Free size for File System

How to find the free size currently FileSystem has, on the disk mounted? I know 'df' lists all the mounted disks, but I am interested to know details for the filesystem, in which currently I am working. (7 Replies)
Discussion started by: videsh77
7 Replies
Login or Register to Ask a Question