Calculating Disc Space


 
Thread Tools Search this Thread
Special Forums Hardware Filesystems, Disks and Memory Calculating Disc Space
# 1  
Old 06-04-2002
Calculating Disc Space

Ok....

Can someone please point me in the right direction.

I simply want to know how to take the results of a dfspace or df command and be able to know how to determine how much disk space is either used or remaining.

1$ dfspace
Filesystem 512-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 32768 19896 40% 1227 15% /
/dev/hd2 802816 277248 66% 1035 11% /usr
/dev/hd9var 32768 22480 32% 201 5% /var
/dev/hd3 65536 44680 32% 137 2% /tmp
/dev/hd1 16384 15568 5% 126 7% /home
/dev/lv00 98304 43992 56% 355 3% /versyss
/dev/lv01 6012928 1989648 67% 5022 1% /versyss/data

1$ df -k
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 16384 9948 40% 1227 15% /
/dev/hd2 401408 138624 66% 11035 11% /usr
/dev/hd9var 16384 11240 32% 201 5% /var
/dev/hd3 32768 22340 32% 137 2% /tmp
/dev/hd1 8192 7784 5% 126 7% /home
/dev/lv00 49152 21996 56% 355 3% /versyss
/dev/lv01 3006464 994824 67% 5022 1% /versyss/data


One section shows 512-blocks and the other shows 1024-blocks

I am sure there is a simple procedure for calculating disk space..

Please help =)
# 2  
Old 06-04-2002
I'd just add up the numbers in the columns...

You can do it rather easily with a Perl script

Code:
#!/usr/bin/perl

open(STATS, "df -k|") || die "$!";

my $lineNumber  = 0;
my $totalUsed   = 0;
my $totalSpace  = 0;

while ($inputLine = <STATS>) {
  if ($lineNumber++ != 0) {  # Skip the first entry of the `df -k` results
    $inputLine =~ s/\s+/ /g; # Force multiple spaces to be a single space for splitting
    my @columns = split(/ /, $inputLine);
    $totalSpace += $columns[1];
    $totalUsed += $columns[2];
  };
};

print "There are a total of $totalSpace 1K Blocks.\n";
print "There are a total of $totalUsed 1K Blocks in use.\n";

That'll turn this:

Code:
FreeBSD:auswipe:/home/auswipe/sample $ df -k
Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
/dev/ad0s1a    128990    83050    35622    70%    /
/dev/ad0s1f    257998      870   236490     0%    /tmp
/dev/ad0s1g  15222640  9194730  4810100    66%    /usr
/dev/ad0s1e    257998   157116    80244    66%    /var
procfs              4        4        0   100%    /proc
linprocfs           4        4        0   100%    /usr/compat/linux/proc

Into this:

Code:
FreeBSD:auswipe:/home/auswipe/sample $ ./freespace
There are a total of 15867634 1K Blocks.
There are a total of 9435674 1K Blocks in use.

You can modify the code as necessary. In this case, I really need to omit the procfs and linprocfs entries as these actually reside on a previously mentioned filesystem and is used for Linux compatibility under FreeBSD.

Any way, that's the jist of it. The rest is up to you.
# 3  
Old 06-04-2002
Thank you for the script, however, what I am looking for.. is the following:

I want to translate 1k blocks into kilobytes or megabytes.

Or rather I want to take the number and calculate the disk space in megabytes or gigabytes.
# 4  
Old 06-04-2002
Using 1K Blocks:

(NumBlocks*1024)/2^20 will yield MegaBytes
(NumBlocks*1024)/2^30 will yield GigaBytes
# 5  
Old 06-05-2002
I don't have perl installed on any of my machines.. seems that the OS comes as a "Base" operating system and 'perl' isn't included. UGHHHHHH!!!!!!

Thanks alot for your help... I'll get it figured out.. =)
# 6  
Old 06-05-2002
1024 kilobytes is a megabyte. So roughly, 1000 kilobytes is a megabyte. When you see something like: 11035 1k blocks are available, simply divide by 1000 in your head. So roughly, you have 11.035 megabytes or just 11 megabytes. That's close enough.

And likewise 6012928 1k blocks is 6012.928 megabytes. Or 6.012928 Gigabytes. Or just 6 Gigabytes. Again, this is fast and it's close enough.

For the record, the real values are
6012928 1k blocks = 5.734 Gigabytes
6012928 1k blocks = 5872 Megabytes
11035 1k blocks = 10.776 Megabytes

You can use the standard unix program bc to get these results. Type "bc" and then press return to start running bc. Then enter, as an example:
scale=3
6012928/1024
Type control d to exit bc when you're done.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Calculating space used in GB for any particular directory in UNIX?

How to Calculating space used in GB for any particular directory in unix Currently I am using : df -h which gives me space for each mout point ldndyn1:/vol/v01/dyn/sbcexp/dyn 1.1T 999G 29G 98% /sbcimp/dyn but I need for some internal particular directory... (3 Replies)
Discussion started by: RahulJoshi
3 Replies

2. Shell Programming and Scripting

Disc space issues and purging of files

Hi All, I am looking forward to create a unix shell script to purge the files. The requirement is: 1) Do df -k and check the current space occupied for the /a1 folder. 2) If the space consumed is greater than 90 %, delete all the DEF* files from a subfolder /a1/archive. Example: df... (4 Replies)
Discussion started by: shilpa_acc
4 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. Shell Programming and Scripting

Calculating server space

I am Connected With 4 servers I want to check the free space available in each server HOW to do this ? (8 Replies)
Discussion started by: pranabrana
8 Replies

5. Shell Programming and Scripting

Calculating server space

I am Connected With 4 servers I want to check the free space available in each server HOW to do this ? Edit/Delete Message (3 Replies)
Discussion started by: pranabrana
3 Replies

6. Filesystems, Disks and Memory

calculating the filesystem space

Hi, Just wanted to confirm that what Im doing is correct to calculate the space allocated to filesystem: >df -k . Filesystem 1024-blocks Free %Used Iused %Iused Mounted on /test 48720000 9337904 81% 14846 1% /home The space allocated = 48720000/1024 =... (1 Reply)
Discussion started by: deepakgang
1 Replies

7. Filesystems, Disks and Memory

Calculating Drive Space Increase

I trying to calculate drive space with RAID. I know the equation is: (n-1)/n * drive capacity but, when I use that my calculations don't come out when I compare to what I already know exists: I have 3 - 18.2gb SCSI drives that contain two logical drives C & D. Using the math, (3-1)/3 * 18.2... (1 Reply)
Discussion started by: JTalbot017
1 Replies

8. Filesystems, Disks and Memory

calculating disk space for growth

what's the best way to calculate the raw disk space in format. the system is a Solaris system using EMC disks- df -k will give me what's used plus available.Now I need the total disk space that the system is using/assigned. Which means I must inventory the raw disks in format. the system uses... (6 Replies)
Discussion started by: sholiver
6 Replies

9. Shell Programming and Scripting

Scripts for calculating size and remaining space of a directory automatically.

I would like to create a script for calculating size and remaining space of a directory automatically every 24 hours, then send an email to report to the admin. * POSIX and PERL are preferred. Can anyone help, please? (1 Reply)
Discussion started by: leonall
1 Replies

10. UNIX for Dummies Questions & Answers

Calculating Disc Space

I need some help in determining disc space. I ran the following commands on my IBM RS6000 server and this is what I get # dfspace Filesystem 512-blocks Free %Used Iused %Iused Mounted on /dev/hd4 32768 19832 40% 1225 15% / /dev/hd2 802816 277256 66% ... (2 Replies)
Discussion started by: Docboyeee
2 Replies
Login or Register to Ask a Question