- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 06:26 AM
08-19-2003 06:26 AM
encounting the sum of all files in
a directory /including files in subdirectories/, in bytes?
High points-level!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 06:29 AM
08-19-2003 06:29 AM
Re: Perl script
Yes, but how about:
du -sk
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 06:33 AM
08-19-2003 06:33 AM
Re: Perl script
find . -depth -exec ll {} \; | grep -v -e total -e drwx | awk '{datotal
+=$5;}END {print datotal}'
Or if you want to break it into two nicer steps:
find . -depth -exec ll {} \; | grep -v -e total -e drwx > useme
awk '{datotal+=$5;}END {print datotal}' < useme
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 06:37 AM
08-19-2003 06:37 AM
Re: Perl script
I think du -s will do. du -sk will give in 1024 byte blocks.
Do you really need a perl script for this.
HTH,
Umapathy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 06:37 AM
08-19-2003 06:37 AM
Re: Perl script
#!/bin/sh
# llsum_size : sum file size for ll result (file or stdin)
#
# usage : llsumsize [ filename ]
# filename : output of the 'll' command
awk '
BEGIN{ total=0; countfile=0; }
{
if(substr($1,1,1)=="-") {
total+=$5;
countfile++;
}
}
END{ totalmb= total / (1024 * 1024 );
printf("llsumsize : nbfiles counted = %d\n",countfile);
printf("llsumsize : total (bytes) = %12d\n",total);
printf("llsumsize : total (Mbytes) = %12.2f\n",totalmb);
} ' $1
Rgds,
JL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 06:38 AM
08-19-2003 06:38 AM
Re: Perl script
For bytes though, you'd want. du -ks will give the output in kilobytes. du -s will output the number of 512 byte blocks.
cd $MYDIR
echo $(( $(du -s . | cut -f1) * 512 ))
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 06:41 AM
08-19-2003 06:41 AM
Re: Perl script
I know HPUX-command "du". :))
But I want exactly Perl-script !!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 07:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 07:20 AM
08-19-2003 07:20 AM
Re: Perl script
#!/usr/bin/perl -w
system("du -sk");
Regards,
Sergejs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 07:59 AM
08-19-2003 07:59 AM
Re: Perl script
#!/usr/local/bin/perl -w
my $path="/home/";
print "\n\nThe sum of all files in a directory '$path' (including files in subdirectories) is ", &Sizes ($path), " bytes \n";
sub Sizes {
my $dir = shift;
my $size = 0;
my $entry;
my @subDirs;
chdir $dir or die " chdir failed ($!)\n";
opendir DIR, "." or die " opendir failed ($!) \n";
while (defined ($entry = readdir DIR)) {
if (-f $entry) {
$size += -s _;
}
elsif (-d _ and $entry ne '.' and $entry ne '..') {
$size += -s _;
push @subDirs, $entry;
}
}
closedir DIR or die " closedir failed ($!)\n";
foreach $dir (@subDirs) {
$size += &Sizes ($dir);
}
chdir '..' or die " chdir .. failed ($!)\n";
return $size;
}
Regards,
Sergejs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 08:20 AM
08-19-2003 08:20 AM
Re: Perl script
my $base = $ARGV[0] || "./";
my $total = 0;
sub addsize {
$total += -s;
}
find(\&addsize, $base);
print "$total\n";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 09:25 AM
08-19-2003 09:25 AM
Re: Perl script
Enjoy, have FUN! H.Merijn