1753771 Members
4875 Online
108799 Solutions
New Discussion юеВ

mtime issue

 
SOLVED
Go to solution
himacs
Super Advisor

mtime issue

Hi Gurus,
I want to list the files with extension .arc older than 1 day.
i have used command
find . -type f -name "*.arc" -mtime +0 -print

it shows files,but with subfolders.

i don want list .arc files from subfolders.

I am interested in the files that are more than one day old and dont wnat to list the files from subfolders.

plz guide us with proper formats..

regards
himacs
10 REPLIES 10
Tingli
Esteemed Contributor

Re: mtime issue

find . -type f -name "*.arc" -mtime +0 | cut -c 3- | grep -v \/
James R. Ferguson
Acclaimed Contributor

Re: mtime issue

Hi Himacs:

Since you don't want to descend into directories that are subordinate to the parent you request, I think I would use Perl:

# cat ./dayoldfiles
#!/usr/bin/perl
use warnings;
use strict;
my ( $dir, $dh, $name );
$dir = $ARGV[0] ? shift : '.';
chdir $dir or die "Can't 'cd' to '$dir': $!\n";
opendir( $dh, $dir ) or die "Can't open '$dir': $!\n";
while ( $name = readdir($dh) ) {
next if $name =~ /^\.\.?$/;
next unless -f $name;
next unless ( -M $name > 1 );
printf "%s%s%s\n", $dir, $dir eq '/' ? '' : '/', $name;
}
1;

...run as:

# ./dayoldfiles /path

or for your current working directory, simply:

# ./dayoldfiles

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: mtime issue

Hi (again):

Oops, I missed the fact (at least by your example) that you want to find only files with the '.arc' extension. Given that, we'll add this line:

next if $name =~ m{\.arc};

...or in total:

# cat ./dayoldfiles
#!/usr/bin/perl
use warnings;
use strict;
my ( $dir, $dh, $name );
$dir = $ARGV[0] ? shift : '.';
chdir $dir or die "Can't 'cd' to '$dir': $!\n";
opendir( $dh, $dir ) or die "Can't open '$dir': $!\n";
while ( $name = readdir($dh) ) {
next if $name =~ m{^\.\.?$};
next unless -f $name;
next if $name =~ m{\.arc};
next unless ( -M $name > 1 );
printf "%s%s%s\n", $dir, $dir eq '/' ? '' : '/', $name;
}
1;

Regards!

...JRF...
Tingli
Esteemed Contributor

Re: mtime issue

Try to make it fancier.

find . -type f -name "*.arc" -mtime +0 -print | sed -n '/^.\/.*\/.*/!p'
James R. Ferguson
Acclaimed Contributor

Re: mtime issue

Hi :

OK, I'm an idiot. You _want_ files with the 'arc' extension, so change the line-11 in my last post:

From:

next if $name =~ m{\.arc};

To:

next unless $name =~ m{\.arc};

/* NO POINTS FOR THIS CORRECTION, PLEASE */

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: mtime issue

> i don want list .arc files from subfolders.

GNU "find" has a "-maxdepth levels" option
which makes it easy to limit the directory
depth of the search. There's also "-prune",
but I usually find it confusing.

A Forum search for keywords like
find prune maxdepth
should find some examples.
himacs
Super Advisor

Re: mtime issue

Hi Admins,

Thanx for ur time..

i will update the status soon..


regards
himacs
James R. Ferguson
Acclaimed Contributor
Solution

Re: mtime issue

Hi:

What's wrong with the solutions offered? You apparently don't want a Perl script and you apparently don't want to investigate the GNU find() [with its enhanced options].

Do you want a solution to your problem or do you want only a _specific_ tool to solve it? Does a screwdriver suffice to drive nails?

...JRF...
himacs
Super Advisor

Re: mtime issue

Hi Jamie,

Its nothing like that i dont want to investigate. In fact my problem was solved by using the one line command
find /data04/pcard_arch/*.arc -type f -name "*.arc" -mtime +0 -print | sed -n '/^.\/.*\/.*/!p'

And about the perl script,m not familiar with scripting.now m checking your script before executing,since mine live server.

Thanks for your wonderful and timely support.I expect the same in future too...Expect more posts from me.