Professional Web Applications Themes

Getting the total size of files matching a pattern? - PERL Miscellaneous

Math55 wrote: > hello, is there a goor mothod to get the total size of special files > in a directory? for example all *.gz and *.html file in /var/log or > something like that. i tried with du -c *.gz but this is not working > as it should. > > any ideas? 1. open the directory you're interested in (perldoc -f opendir) 2. loop through all files in the open directory... (perldoc -f readdir) 3. ...ignoring the files you're not interested in (perldoc -f grep) 4. add the size of the files in the loop (perlodc -f -x) ...

  1. #1

    Default Re: Getting the total size of files matching a pattern?

    Math55 wrote:
    > hello, is there a goor mothod to get the total size of special files
    > in a directory? for example all *.gz and *.html file in /var/log or
    > something like that. i tried with du -c *.gz but this is not working
    > as it should.
    >
    > any ideas?

    1. open the directory you're interested in (perldoc -f opendir)

    2. loop through all files in the open directory... (perldoc -f readdir)

    3. ...ignoring the files you're not interested in (perldoc -f grep)

    4. add the size of the files in the loop (perlodc -f -x)

    5. print the result after the loop terminates (perldoc -f print)



    1, 2 and 3 can also be done using File::Find (perldoc File::Find). Perhaps
    File::Find can do 4 as well, but I'm not sure.


    --
    Cheers,
    Bernard
    --
    echo 42|perl -pe '$#="Just another Perl hacker,"'

    Bernard El-Hagin Guest

  2. #2

    Default Re: Getting the total size of files matching a pattern?

    Math55 <magelordt-online.de> wrote:
    > is there a goor mothod to get the total size of special files
    > in a directory? for example all *.gz and *.html file in /var/log or

    perl -e '$i += -s for ARGV; print "$i\n"' /var/log/*.html /var/log/*.gz

    or

    perl -e '$i += -s for </var/log/*.html /var/log/*.gz>; print "$i\n"'


    --
    Tad McClellan SGML consulting
    [email]tadmcaugustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

Similar Threads

  1. pattern matching
    By Tad McClellan in forum PERL Beginners
    Replies: 30
    Last Post: June 23rd, 07:42 PM
  2. Pattern Matching Operators
    By Prasad Karpur in forum PERL Beginners
    Replies: 2
    Last Post: October 5th, 04:21 PM
  3. Pattern matching username
    By perl@swanmail.com in forum PERL Beginners
    Replies: 1
    Last Post: September 30th, 05:37 PM
  4. matching the pattern (strings)
    By MJS in forum PERL Beginners
    Replies: 0
    Last Post: September 28th, 07:04 PM
  5. [PHP] mysql Pattern Matching
    By Cpt John W. Holmes in forum PHP Development
    Replies: 1
    Last Post: September 5th, 06:42 PM

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