crazy-duck has asked for the wisdom of the Perl Monks concerning the following question:

Hi Team, Could any one please let me know what is command that can be used to know the used percentage of a directory located on a Linux file system /opt/OV/abc, the directory name is abc

Replies are listed 'Best First'.
Re: Directory used % in Linux ?
by Anonymous Monk on Jan 31, 2014 at 10:29 UTC
     [man://df] df

      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

        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)

Re: <p>Directory used % in Linux </p>
by pvaldes (Chaplain) on Jan 31, 2014 at 18:39 UTC

    Untested but "should work"

    opendir $mydir, "/somedir"; chdir $mydir; print `du -ha $mydir`; closedir $mydir;
    sh: 1: Syntax error: "(" unexpected

    ups, or maybe not :-)

    Well... this is awful, but works

    perl -e 'system("du -ha /somedir");'

    but this don't go, Opendir issue probably. I'm surely doing a very silly mistake

    perl -e 'opendir (my $dir, "/somedir"); chdir $dir; system ("du -ha $dir"); closedir $dir;'
      a dirhandle is not a dirpath, you're using a system with a dirhandle, maybe you want '.' instead of $dir?

        Yup, you are right. But '.' was too trivial, that I wanted for my example the abstraction: "the current directory".

        With some delay, but a little research today led me to the solution. It was more easy than expected.

        use Cwd qw(); use strict; my $current = Cwd::cwd(); print `du -ha $current\n`;