Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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

by FloydATC (Deacon)
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

Replies are listed 'Best First'.
Re^3: <p>Directory used % in Linux </p>
by LanX (Bishop) 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.


        «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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1072821]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2018-04-26 19:50 GMT
Find Nodes?
    Voting Booth?