Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: <p>Directory used % in Linux </p>

by FloydATC (Chaplain)
on Jan 31, 2014 at 10:37 UTC ( #1072821=note: print w/ replies, xml ) Need Help??


in reply to Re: Directory used % in Linux ?
in thread Directory used % in Linux

df only works if that directory happens to be a mountpoint. Otherwise, you'll have to use du, parse the output and calculate the percentage yourself.

-- FloydATC

Time flies when you don't know what you're doing


Comment on Re^2: <p>Directory used % in Linux </p>
Select or Download Code
Re^3: <p>Directory used % in Linux </p>
by LanX (Canon) on Jan 31, 2014 at 11:01 UTC
    You seem to understand the OP ....

    Please tell me, what is "used percentage of a directory" supposed to mean if its not a mount point?

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      I've had this problem a few times; the partition where my "/var/log" directory lives is filling up fast, what application (= sub directory) is eating up all the disk space?

      Just guessing the OP has a similar task. It could be home directories, database partitions, whatever.

      -- FloydATC

      Time flies when you don't know what you're doing

      Hi Rolf, We are looking for the amount of disk space used by a directory on a mounted filesystem, for example if a filesystem is allocation for 8gb space and on that file system if I have directory call ABC consuming 4gb space, which means 50% of the space consumed by the directory ABC on that filesystem, can we get this sort information?

        Like this ( i remember this has been mentioned already):

        somehost:~ # mount | grep mysql /dev/sda3 on /var/lib/mysql type ext3 (rw,acl,user_xattr) somehost:~ # df -h /var/lib/mysql/ Filesystem Size Used Avail Use% Mounted on /dev/sda3 215G 75G 129G 37% /var/lib/mysql

        Or a variation of it.

        I read this: 37% (75G of 215G) of /var/lib/mysql are used".

        Or i didn't understand the problem, who knows.

        Karl

        «The Crux of the Biscuit is the Apostrophe»

        As I already pointed out, the "du" tool can help you with this by reporting directory sizes but you will have to calculate percentages yourself.

        Here's an example that does pretty much what you describe, go ahead and hammer it into the shape you want:

        #!/usr/bin/perl use strict; use warnings; my $dir = join(' ', map { '"'.$_.'"' } @ARGV) || "*"; # Use arguments +or default to pwd my @lines = qx(du -sc $dir); # Get sizes in bytes, with total my ($total) = split(/\s/, pop @lines); # Get total number of bytes foreach my $line (@lines) { if ($line =~ /(\d+)/) { printf("%6.2f%%\t%s", $1 * 100 / $total, $line); # Prefix % } }
        -- FloydATC

        Time flies when you don't know what you're doing

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1072821]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-10-25 17:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (146 votes), past polls