Professional Web Applications Themes

Getting the total size of a directory - PERL Beginners

I'm running out of web space and want to write a script that tell me the size of certain directories so I can see where the hog is. Can anyone give me some quick code?...

  1. #1

    Default Getting the total size of a directory

    I'm running out of web space and want to write a script that tell me the size
    of certain directories so I can see where the hog is.

    Can anyone give me some quick code?

    Motherofperls@aol.com Guest

  2. #2

    Default Re: Getting the total size of a directory

    On Sun, 4 Jan 2004 [email]Motherofperlsaol.com[/email] wrote:
    > I'm running out of web space and want to write a script that tell me the size
    > of certain directories so I can see where the hog is.
    >
    > Can anyone give me some quick code?
    A shell script might be even faster with du -s /tmp | sort -n

    Rus

    --
    e: [email]supportvpscolo.com[/email]
    t: 1-888-327-6330
    [url]www.jvds.com[/url] - Root on your own box
    [url]www.vpscolo.com[/url] - Your next hosting company
    Rus Foster Guest

  3. #3

    Default RE: Getting the total size of a directory

    I think there was a very recent thread on this, but here's one way using File::Find, taking a little from a result I found by arching Google:

    ##################################
    use File::Find;
    use strict;
    my $dir = $ARGV[0];
    my $size;
    find(sub{ -f and ( $size += -s ) }, $dir );
    $size = sprintf("%.02f",$size / 1024 / 1024);
    print "Directory '$dir' contains $size MB\n";
    ##################################

    -----Original Message-----
    From: [email]Motherofperlsaol.com[/email] [mailto:Motherofperlsaol.com]
    Sent: Sun 1/4/2004 6:10 PM
    To: [email]beginnersperl.org[/email]
    Cc:
    Subject: Getting the total size of a directory



    I'm running out of web space and want to write a script that tell me the size
    of certain directories so I can see where the hog is.

    Can anyone give me some quick code?


    Tim Johnson Guest

  4. #4

    Default Re: Getting the total size of a directory

    >>>>> "Tim" == Tim Johnson <tjohnsonsandisk.com> writes:

    Tim> find(sub{ -f and ( $size += -s ) }, $dir );

    Beware that -s has only a rough correlation with the actual disk a
    file takes. You want (stat)[12] for that. The -s number will be far
    too huge for holey files (blocks aren't allocated), and a little too
    low for large files (indirect blocks).

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    Randal L. Schwartz Guest

  5. #5

    Default Getting the total size of a directory

    I got my problem solved. Thanks for this comment Tim! You're brilliant!

    -MacWarrior-
    -----------------------------------------------------------------------------------

    I think there was a very recent thread on this, but here's one way using File::Find, taking a little from a result I found by arching Google:

    ##################################
    use File::Find;
    use strict;
    my $dir = $ARGV[0];
    my $size;
    find(sub{ -f and ( $size += -s ) }, $dir );
    $size = sprintf("%.02f",$size / 1024 / 1024);
    print "Directory '$dir' contains $size MB\n";
    ##################################

    -----Original Message-----
    From: [email]Motherofperlsaol.com[/email] [mailto:Motherofperlsaol.com]
    Sent: Sun 1/4/2004 6:10 PM
    To: [email]beginnersperl.org[/email]
    Cc:
    Subject: Getting the total size of a directory

    I'm running out of web space and want to write a script that tell me the size
    of certain directories so I can see where the hog is.

    Can anyone give me some quick code?
    MacWarrior Guest

Similar Threads

  1. Directory Size
    By Chris Blake in forum PHP Development
    Replies: 1
    Last Post: August 15th, 10:55 AM
  2. Setting total db size to a variable.
    By Jason Martyn in forum PHP Development
    Replies: 8
    Last Post: July 22nd, 11:49 AM
  3. Cast Members Size Vs. Total Movie Size
    By PaulaJune webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 0
    Last Post: July 22nd, 06:33 AM
  4. [PHP] Setting total db size to a variable.
    By Curt Zirzow in forum PHP Development
    Replies: 1
    Last Post: July 20th, 05:10 AM
  5. Getting the total size of files matching a pattern?
    By Bernard El-Hagin in forum PERL Miscellaneous
    Replies: 1
    Last Post: June 30th, 11:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139