1752786 Members
6003 Online
108789 Solutions
New Discussion юеВ

Re: Help with Perl

 
SOLVED
Go to solution
Yvonne Butler
Regular Advisor

Help with Perl

Hi

Some very kind forum members helped me put together this perl command below which I'm using to tell me how many files are in a directory which are 15 minutes older than the system date:

perl -MFile::Find -le '$path=shift||qq(.);find(sub{print $File::Find::name if -f $_ && -M _ >= ((15*60)/(60*60*24))},$path)' /oraother/tes/comms/outtray | wc -l

But what I need now is to modify this command to find out how many files that are not of a "0" byte size in a given directory. I don't know Perl I'm afraid so don't know where to start. Any suggestions would be very appreciated.

Thanks
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: Help with Perl

Hi Yvonne:

This is quite simple:

# perl -MFile::Find -le '$path=shift||qq(.);find(sub{print $File::Find::name if -f $_ && -s _},$path)'

...returns the non-zero size files. Change the '-s' to '-z' to return files of zero size.

For things like this, Perl is probably overkill. You could simply do:

# find . -type f ! -size 0c

...to return files with size greater than zero and:

# find . -type f -size 0c

...to return files of size zero.

Regards!

...JRF...
Suraj K Sankari
Honored Contributor

Re: Help with Perl

Hi,
To find out all zero bytes file use find command

#find /home -type f -size 0c -exec ls -l {} \;

Suraj
Yvonne Butler
Regular Advisor

Re: Help with Perl

Ahh I haven't explained myself properly, what I actually need to still to get a total number of files in a given directory which are not of a zero byte size and which are 15 minutes or more older than the system date.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Help with Perl

Hi (again) Yvonne:


> what I actually need to still to get a total number of files in a given directory which are not of a zero byte size and which are 15 minutes or more older than the system date.

Ah. that makes better sense:

# perl -MFile::Find -le '$path=shift||qq(.);find(sub{print $File::Find::name if -f $_ && -s _ && -M _ >= ((15*60)/(60*60*24))},$path)'

...which simply adds (ands) the test for file size that I first showed.

Regards!

...JRF...
Yvonne Butler
Regular Advisor

Re: Help with Perl

Wow JRF you're good - that's it exactly, thanks yet again!