Operating System - HP-UX
1836995 Members
1933 Online
110111 Solutions
New Discussion

How to find file with mtime < 1 day

 
SOLVED
Go to solution
violin
Occasional Advisor

How to find file with mtime < 1 day

Hello Folks,

I want to know how to find or list files
with atime/mtime/ctime less than one day.

'Cause our application had created lots of logs yesterday , and I had to find out and mv to another dir ,

$ ls -l o329510.out
-rw-r--r-- 1 erpmgr dba 16848 May 14 13:54 o329510.out
$
$ find . -mtime +1 -print
$ ==> Nothing print cause mtime less than one day.

Somebody could tell me how to find or ls.
like :
find . -mtime ??? -exec mv /home/erpmgr/bak {}\;
ls -l | grep "May 14" | exec mv ???


Thanks in advance.

Violin.
12 REPLIES 12
Mark Fenton
Esteemed Contributor

Re: How to find file with mtime < 1 day

# find /path/to/files -type f -mtime 0 ...

will find all files along path with mtime less than 24 hours.

Mark

S.K. Chan
Honored Contributor

Re: How to find file with mtime < 1 day

-rw-r--r-- 1 erpmgr dba 16848 May 14 13:54 o329510.out

You should be able to use "-mtime 0" for your purpose.

# find . -mtime 0 -print

OR

You can create a reference file .. for example

# touch 05140001 ref
# find . -newer ref -print
violin
Occasional Advisor

Re: How to find file with mtime < 1 day

Thank you,

BUT mtime 0 will list files created today.
Is there other option , maybe by X hours?

Violin.
Helen French
Honored Contributor

Re: How to find file with mtime < 1 day

Hi,

You can use the -newer option with find by specifying to a file. Check the man pages for details.

HTH,
Shiju
Life is a promise, fulfill it!
Michael Tully
Honored Contributor

Re: How to find file with mtime < 1 day

Hi,

Have a look at the -newer using the additional time value option.

# find -newer tv1 tv2 file

HTH
~Michael
Anyone for a Mutiny ?
Animesh Chakraborty
Honored Contributor

Re: How to find file with mtime < 1 day



touch -t 05140001 /tmp/XX
find /dirA/subdirB -newer /tmp/XX | mv /newdir
Did you take a backup?
S.K. Chan
Honored Contributor

Re: How to find file with mtime < 1 day

OK lets take an example, you may be able to use this for your needs ..
May14 13:54 filea
May14 13:55 fileb
May14 14:01 filec
May14 14:12 filed

Assuming all files are dated May14. Say you want to list all files created between 13:53 and 13:56, then you can do this ..
# cd /tmp
# touch 05141353 refa
# touch 05141356 refb

Now in that dir, you would run ..

# find . \( -newer /tmp/refa -a ! newer /tmp/refb \) -print

and that should just list "filea" and "fileb"
violin
Occasional Advisor

Re: How to find file with mtime < 1 day

Thanks,

BUT ERRORS:
$find . \( -newer /tmp/refa -a ! newer /tmp/refb \) -print
find: bad option newer
S.K. Chan
Honored Contributor
Solution

Re: How to find file with mtime < 1 day

I'm sorry ..my typo .. the 2nd "newer" should also has a "-" like so ..

# find . \( -newer /tmp/refa -a ! -newer /tmp/refb \) -print

violin
Occasional Advisor

Re: How to find file with mtime < 1 day

Thanks so much,
It works, BUT another question:

Can I find and then mv to other directory?
find . \( -newer /tmp/refa -a ! -newer /tmp/refb \) -exec mv /bak {} \;

I tried and retunred error:
mv: ./o329545.out: rename: Not a directory
mv: ./o329547.out: rename: Not a directory

Thanks again.

Violin.

S.K. Chan
Honored Contributor

Re: How to find file with mtime < 1 day

Sure .. it should be like this ..

# find . \( -newer /tmp/refa -a ! -newer /tmp/refb \) -exec mv {} /bak \;

I'm glad it worked for you :)

S.K. Chan
Honored Contributor

Re: How to find file with mtime < 1 day

Also remember to assign points, that's the least you can do. Thanks .. :)