Ask a Question related to PERL Beginners, Design and Development.
-
Dan Muey #1
Portable unix du command
Howdy group.
I have a need to get the size of a directory.
I could just execute unix's du command (my $sz = `du -sh /usr`;)
but was wondering if there's a better way to do it that is more portable.
I looked on cpan but didn't see anythign that jumped out at me.
TIA
Dan
Dan Muey Guest
-
Wrapping Unix Command into Perl
I am trying to wrap the following Unix command into perl and having a few issues: find /var/spool/Tivoli/backups -name "DB_*" -mtime +10 -print... -
I need help on a command for my Unix class---PLEASE ! ?
I've got a file that contains one line of text. The line looks like this: 34 That's all. When I try to echo the results in a sentence,... -
what is different between SIZE and RES of unix command top?
Hi there, i saw the man page for top command SIZE : the total size of the process(text, data, and stack) RES : the current amount of resident... -
HELP NEEDED WITH UNIX COMMAND MAN
HI Hey i have a quick question. How do we redirect the output of the man command to file which does not have junk or control charaters. i think... -
Portable Unix utility scripts
The Typhoon Toolkit (http://www.raycosoft.com/rayco/products/typhoon) contains about 90 portable utility programs for text processing, file and... -
Drieux #2
Re: Portable unix du command
On Tuesday, Nov 18, 2003, at 09:20 US/Pacific, Dan Muey wrote:
a part of the problem is that the 'du' command> Howdy group.
>
> I have a need to get the size of a directory.
> I could just execute unix's du command (my $sz = `du -sh /usr`;)
> but was wondering if there's a better way to do it that is more
> portable.
> I looked on cpan but didn't see anythign that jumped out at me.
>
is basically implemented differently between the
BSD and SYSV styles of unix. One strategy that
I have adopted when I am looking at a 'common'(HA!)
unix utility that I would like to use, and
in your illustration, the 'flags' to it, that
are problematic, I create a wrapper class.
a quicky way to think about your problem would
be my WhackJob for dealing with my 'favorite'
set of flags to the 'ps' command:
cf
<http://www.wetware.com/drieux/CS/Proj/PID/>
To be honest, I use something like that, but more
cleaned up in a project I have. The trick of
course is getting 'illustrations' from all of the
OS's that you will want to be 'portable' with.
HTH.
ciao
drieux
---
Drieux Guest
-
Dan Muey #3
RE: Portable unix du command
Thanks. What I really want to do is avoid system commands completely.> On Tuesday, Nov 18, 2003, at 09:20 US/Pacific, Dan Muey wrote:
>> /usr`;) but> > Howdy group.
> >
> > I have a need to get the size of a directory.
> > I could just execute unix's du command (my $sz = `du -sh> portable.> > was wondering if there's a better way to do it that is more>> > I looked on cpan but didn't see anythign that jumped out at me.
> >
> a part of the problem is that the 'du' command
> is basically implemented differently between the
> BSD and SYSV styles of unix. One strategy that
> I have adopted when I am looking at a 'common'(HA!)
> unix utility that I would like to use, and
> in your illustration, the 'flags' to it, that
> are problematic, I create a wrapper class.
>
> a quicky way to think about your problem would
> be my WhackJob for dealing with my 'favorite'
> set of flags to the 'ps' command:
>
> cf
> <http://www.wetware.com/drieux/CS/Proj/PID/>
>
> To be honest, I use something like that, but more
> cleaned up in a project I have. The trick of
> course is getting 'illustrations' from all of the
> OS's that you will want to be 'portable' with.
>
I could always traverse the directory adding the size of each file
together and do that all in Perl with no system commands but I figured
there'd already be a Module or something like this, so I want to do it
that way. Somthign like:
my $sz = $module->size("/home/joemama");
# return sixze of file or of entire directory if specified file is a directory
> HTH.
>
> ciao
> drieuxDan Muey Guest
-
John W. Krahn #4
Re: Portable unix du command
Dan Muey wrote:
You mean something like (untested):>
> Thanks. What I really want to do is avoid system commands completely.
> I could always traverse the directory adding the size of each file
> together and do that all in Perl with no system commands but I figured
> there'd already be a Module or something like this, so I want to do it
> that way. Somthign like:
use File::Find;
my $dir = '/some/dir';
my $size;
find( sub { -f and ( $size += -s _ ) }, $dir );
print "Directory '$dir' contains $size bytes\n";
John
--
use Perl;
program
fulfillment
John W. Krahn Guest
-
Drieux #5
Re: Portable unix du command
On Tuesday, Nov 18, 2003, at 09:35 US/Pacific, Dan Muey wrote:
[..]I can appreciate the desire, but remember that>
> Thanks. What I really want to do is avoid system commands completely.
> I could always traverse the directory adding the size of each file
> together and do that all in Perl with no system commands but I figured
> there'd already be a Module or something like this, so I want to do it
> that way. Somthign like:
>
> my $sz = $module->size("/home/joemama");
> # return sixze of file or of entire directory if specified file is a
> directory
"systems applications" - such as 'du' and 'ps'
are there so that folks do not have to know all
of the OS specific underlying 'system calls' that
will flop into 'kernal space'.
The fine folks who are maintaining the Proc::Table
module deliver XS code that gets converted into
the 'c' code that becomes the dynamically loadable
library that is referenced in the "perl module"....
Which is why I opted to take the 'sillier' path
of simply working out which command line arguments
were the 'right ones' for Me based upon the four
or five basic *nix versions that I work with and
then go through the process that way.
If you want to have fun, then you will of course
want to become friends with stat(), cf perldoc -f stat
and/or read the POSIX module, cf perldoc POSIX.
Or download a copy of the open source for 'du'
and work out which parts of it you want to use
as the basis for your own perl module.
ciao
drieux
---
Drieux Guest
-
Bob Showalter #6
RE: Portable unix du command
Dan Muey wrote:
There's a group working on implementing a number of Unix utilities in Perl.> Howdy group.
>
> I have a need to get the size of a directory.
> I could just execute unix's du command (my $sz = `du -sh /usr`;)
> but was wondering if there's a better way to do it that is
> more portable.
> I looked on cpan but didn't see anythign that jumped out at me.
Here's their du page:
[url]http://www.perl.com/language/ppt/src/du/index.html[/url]
I don't know how portable it is...
Bob Showalter Guest
-
Dan Muey #7
RE: Portable unix du command
> Dan Muey wrote:
Awesome John! Works splendedly, this is exactly what I needed!> completely.> >
> > Thanks. What I really want to do is avoid system commands> but I figured> > I could always traverse the directory adding the size of each file
> > together and do that all in Perl with no system commands> want to do it> > there'd already be a Module or something like this, so I>> > that way. Somthign like:
> You mean something like (untested):
>
> use File::Find;
>
> my $dir = '/some/dir';
> my $size;
>
> find( sub { -f and ( $size += -s _ ) }, $dir );
>
> print "Directory '$dir' contains $size bytes\n";
>
>
>
> John
> --
> use Perl;
> program
> fulfillmentDan Muey Guest
-
David #8
RE: Portable unix du command
Dan Muey wrote:
[snip]>>> On Tuesday, Nov 18, 2003, at 09:20 US/Pacific, Dan Muey wrote:
>>>> /usr`;) but>> > Howdy group.
>> >
>> > I have a need to get the size of a directory.
>> > I could just execute unix's du command (my $sz = `du -sh>> portable.>> > was wondering if there's a better way to do it that is more>> > I looked on cpan but didn't see anythign that jumped out at me.
>> >
good decision.> Thanks. What I really want to do is avoid system commands completely.
try Filesys::DiskFree> I could always traverse the directory adding the size of each file
> together and do that all in Perl with no system commands but I figured
> there'd already be a Module or something like this, so I want to do it
> that way. Somthign like:
>
> my $sz = $module->size("/home/joemama");
#!/usr/bin/perl -w
use strict;
use Filesys::DiskFree;
my $h = Filesys::DiskFree->new;
$h->df;
$h->device('/usr');
print "/usr has ",$h->avail('/usr')," bytes available\n";
__END__
prints:
/usr has 111111111 bytes available
david
--
s,.*,<<,e,y,\n,,d,y,.s,10,,s
..ss.s.s...s.s....ss.....s.ss
s.sssss.sssss...s...s..s....
....s.ss..s.sss..ss.s....ss.s
s.sssss.s.ssss..ss.s....ss.s
...s..sss.sssss.ss.sss..ssss.
...sss....s.s....ss.s....ss.s
,....{4},"|?{*=}_'y!'+0!$&;"
,ge,y,!#:$_(-*[./<-@{-},b-t,
..y...,$~=q~=?,;^_#+?{~,,$~=~
y.!-&*-/:-@^_{}.a-t ().;s,;,
);,g,s,s,$~s,g,y,y,%,,g,eval
David Guest
-
R. Joseph Newton #9
Re: Portable unix du command
david wrote:
On a Unix system. unfortunately, the module is not that portable, depending> Dan Muey wrote:
>
> try Filesys::DiskFree
>
> #!/usr/bin/perl -w
> use strict;
>
> use Filesys::DiskFree;
>
> my $h = Filesys::DiskFree->new;
>
> $h->df;
> $h->device('/usr');
>
> print "/usr has ",$h->avail('/usr')," bytes available\n";
>
> __END__
>
> prints:
>
> /usr has 111111111 bytes available
on the Unix df command.
Joseph
R. Joseph Newton Guest



Reply With Quote

