Operating System - HP-UX
1827089 Members
2903 Online
109713 Solutions
New Discussion

find: how to find files created from 4 to 2 days ago

 
SOLVED
Go to solution
KRI
Advisor

find: how to find files created from 4 to 2 days ago

Hi,
I want to find all files created 1,2 and 3 days ago, but not (24h * 1), (24h * 2), (24h * 3) ago from now.
Simply all files created yesterday, 1 day befor yesterday and 2 days before yesterday.
I have to use standard find (HP-UX 11.00)(not GNU)!
How can I use -mtime switch ?

Example:
========

My files:
-rw------- 1 user user 123456 Mar 10 00:01 1file
-rw------- 1 user user 123456 Mar 10 16:00 2file
-rw------- 1 user user 123456 Mar 11 06:00 3file
-rw------- 1 user user 123456 Mar 11 12:00 4file
-rw------- 1 user user 123456 Mar 12 06:00 5file
-rw------- 1 user user 123456 Mar 12 12:00 6file
-rw------- 1 user user 123456 Mar 13 06:00 7file
-rw------- 1 user user 123456 Mar 13 16:00 8file
-rw------- 1 user user 123456 Mar 13 23:30 9file

When I start find statament (find . -mtime -3 -mtime +0 -exec ls -la {} \;) at 13:30 I will get:

-rw------- 1 user user 123456 Mar 11 12:00 4file
-rw------- 1 user user 123456 Mar 12 06:00 5file
-rw------- 1 user user 123456 Mar 12 12:00 6file
-rw------- 1 user user 123456 Mar 13 06:00 7file

but I want:

-rw------- 1 user user 123456 Mar 11 06:00 3file
-rw------- 1 user user 123456 Mar 11 12:00 4file
-rw------- 1 user user 123456 Mar 12 06:00 5file
-rw------- 1 user user 123456 Mar 12 12:00 6file
-rw------- 1 user user 123456 Mar 13 06:00 7file
-rw------- 1 user user 123456 Mar 13 16:00 8file
-rw------- 1 user user 123456 Mar 13 23:30 9file

KRI
13 REPLIES 13
Peter Kloetgen
Esteemed Contributor

Re: find: how to find files created from 4 to 2 days ago

Hi Krzysztof,

how about using a reference file?

touch time_you_want file_name

find /path -newer file_name

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
KRI
Advisor

Re: find: how to find files created from 4 to 2 days ago

Hi Peter !

I can not use touch to change files mtime because this files are an archive and can not be changed.

In the directory I have over than 100000 files and I must find some of them.

KRI
federico_3
Honored Contributor

Re: find: how to find files created from 4 to 2 days ago


touch 0203100000 file ( this will create file with data 10 Mar 2002 at 00:00 )

find DIR -newer file -exec ll {} \; > file2
This will move the files newer than file in file2

Now you have to find files listed in file2 older than yesterday

cat file2 | grep -v 13 | grep -v 14


Ciao
Federico
Peter Kloetgen
Esteemed Contributor

Re: find: how to find files created from 4 to 2 days ago

Hi Krzysztof,

the touch- command is only used to create a reference- file!

Look at the format in the posting of Frederico.

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
KRI
Advisor

Re: find: how to find files created from 4 to 2 days ago

Gentelments !
I realy have over then 100000 in one directory and I want find same of them.
Some files was created yasterday, some week ago, some 2 weeks ago, some 2 years ago etc.
Now I must find files created for example from 01-01-2000 do 30-06-2000. How can I touch files when I do not know this files are, and what are named etc.

Hello from Poland
KRI
Peter Kloetgen
Esteemed Contributor

Re: find: how to find files created from 4 to 2 days ago

Hi Krzysztof,

once again, you use the file, which you create with the touch- command only as ONE time- reference- file.

pwd

--> where_ever_you_want

touch 0203100000 file

the next is one command line:

find /archive -newer /where_ever_you_want/file -exec ll {}; #end of command

Of course, you can pipe this or redirect into a file and work with it, perhaps to filter something out with cut or grep commands.

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
H.Merijn Brand (procura
Honored Contributor

Re: find: how to find files created from 4 to 2 days ago

This script answers your original question. What is does, is step back in time to 00:00:00 (the start of this day) and from that point in time finds files modified between zero (yesterday) and 2 days. So the '-M $_ > 0' is the upper limit (in days, with fraction, so 1.5 is one day and 12 hours), or the newest file, and the '-M _ <= 2' is the lower limit (the oldest file). Play with 0 and 2 to shift the limits, or add your own options to allow command line arguments.

# pfind .
./3file
./4file
./5file
./6file
./7file
./8file
./9file
# cat pfind
#!/opt/perl/bin/perl

use File::Find;

$^T -= $^T % 86400;
find (sub { -M $_ > 0 && -M _ <= 2 and print "$File::Find::name\n"; }, @ARGV);
#

HTH
Enjoy, Have FUN! H.Merijn
KRI
Advisor

Re: find: how to find files created from 4 to 2 days ago

Peter !
Yes, now I understud !
I very tired ... sory.
But I need -older switch too :-).
I must find file created from A-date to B-date.
-newer switch is good to tell find about A-date.
What about B-date ?

KRI
Peter Kloetgen
Esteemed Contributor

Re: find: how to find files created from 4 to 2 days ago

Hi Krzysztof,

With the -newer option you get everything, from a specified time on. Therefor i mentioned, that you could now do something with the output of this command. I would direct it into a file first. (don't know how much matches you will have.) Then you simply have to make your match more precisely. For example you could do a command:

grep -v dates_you_don't_want /rederected_file

this would give you the output you want. Even better work would this with awk.

Allways stay on the bright side of life!

Peter

p.s. go to bed if possible and retry tomorrow
I'm learning here as well as helping
KRI
Advisor

Re: find: how to find files created from 4 to 2 days ago

Thanks Peter, procura and all of You !
1. Perl
I do not have /opt/perl/bin/perl
but /usr/contrib/bin/perl, but not run corectly.
pfind[3]: use: not found
pfind[5]: $^T: not found
pfind[5]: syntax error at line 6 : `(' unexpected

2. Peter !
I have my project ready in 99% and if I'll want to change this, I must start from begin. Ohhh ! I'm in trouble now !

KRI
P.S.
Sleep - dream :)
Robin Wakefield
Honored Contributor
Solution

Re: find: how to find files created from 4 to 2 days ago

Hi Krzysztof,

You could create 2 flag files, one for the "before" date and one for the "since" date:

# touch 200203031000 file1
# touch 200203071000 file2
# ls -l file*
-rw-rw-r-- 1 root sys 0 Mar 3 10:00 file1
-rw-rw-r-- 1 root sys 0 Mar 7 10:00 file2
# find /tmp -newer file1 -a ! -newer file2 | xargs ls -l
-rw-rw-r-- 1 wakefir users 89 Mar 4 16:36 /tmp/60days.sh
-rwxr-xr-x 1 root sys 108 Mar 6 16:27 /tmp/checkjoin
-rw-r--r-- 1 root sys 346 Mar 7 06:26 /tmp/dirchk.log.14484
-rw-r--r-- 1 root sys 346 Mar 5 06:45 /tmp/dirchk.log.170
-rw-r--r-- 1 root sys 346 Mar 4 06:29 /tmp/dirchk.log.26323
-rw-r--r-- 1 root sys 346 Mar 6 06:26 /tmp/dirchk.log.7540
-rwxr-xr-x 1 root sys 260 Mar 7 09:59 /tmp/f.sh
-rwxr-xr-x 1 root sys 18 Mar 5 16:12 /tmp/get_in.sh

Rgds, Robin.
H.Merijn Brand (procura
Honored Contributor

Re: find: how to find files created from 4 to 2 days ago

You've got an ***OLD*** version of perl, shipped with HP-UX 10.20 and HP-UX 11.00 until Sep 2001

As of Sep 2001 (application CD 5012-7954) perl-5.6.1 (the latest stable release) is available for free.

Please install that version in order to enjoy it's power.

You can get precompiled versions for both 10.20 and 11.00 on the HP-UX software mirrors, for exaple from here: http://hpux.tn.tudelft.nl/hppd/hpux/Languages/perl-5.6.1/
Enjoy, Have FUN! H.Merijn
KRI
Advisor

Re: find: how to find files created from 4 to 2 days ago

Thanks !
Simple things are superb !

KRI