Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

-mtime does not return the expected results

SOLVED
Go to Solution
Advisor

-mtime does not return the expected results

 

 

Hi All,

 

OS :- HPUX 11.11

 

I was trying to use this -mtime attribute to get the files older then n days. But, when I do run this, It'll display all the files, irrespetive of , what is being mentioned. The below code, tried to fetch files older then 14 days, but it is strange to see, it's returning all the files. Please suggest, if I did any thing wrong ??

 

 find . -type f -mtime +14 -exec | ls -ltr

      12933 Jul 16 04:04 qa02_reco_4513.trc
        577 Jul 17 02:30 qa02_lgwr_21693.trc
        577 Jul 17 18:08 qa02_lgwr_13310.trc
        575 Jul 24 02:30 qa02_lgwr_6387.trc
        575 Jul 24 14:54 qa02_lgwr_4182.trc
      12825 Jul 29 14:41 qa02_reco_4493.trc
        577 Jul 31 02:31 qa02_lgwr_27979.trc
        577 Jul 31 21:16 qa02_lgwr_15239.trc
      25020 Aug  5 22:49 qa02_reco_4487.trc
        575 Aug  7 02:30 qa02_lgwr_4826.trc
        577 Aug  7 23:36 qa02_lgwr_18840.trc
        575 Aug 14 02:30 qa02_lgwr_1376.trc
        577 Aug 14 20:41 qa02_lgwr_15341.trc
      25572 Aug 20 00:33 qa02_reco_4525.trc
        575 Aug 21 02:30 qa02_lgwr_3738.trc
        577 Aug 21 22:07 qa02_lgwr_28938.trc
      12825 Aug 26 22:25 qa02_reco_4518.trc
        575 Aug 28 02:30 qa02_lgwr_1917.trc
        575 Aug 28 20:51 qa02_lgwr_8401.trc
        930 Sep  2 00:29 qa02_j000_25855.trc
        930 Sep  3 00:32 qa02_j000_13883.trc
      12933 Sep  3 08:51 qa02_reco_4507.trc
        577 Sep  4 02:30 qa02_lgwr_29439.trc
        577 Sep  4 22:14 qa02_lgwr_27388.trc
      12933 Sep 10 01:04 qa02_reco_4500.trc
        575 Sep 11 02:30 qa02_lgwr_4959.trc
        577 Sep 11 23:03 qa02_lgwr_28954.trc
    3978306 Sep 14 06:48 alert_qa02.log
      11393 Sep 14 06:48 qa02_reco_4522.trc


 

Regards

Hare Krishna

 

 

1 ACCEPTED SOLUTIONS
Acclaimed Contributor Acclaimed Contributor

Re: -mtime does not return the expected results

[ Edited ]

>The other option you have is to do:

 

The problem with xargs is the buffer is trivially small compared to the ~1 M or so in -exec ... +.

The ll -t output will be in smaller chunks, so won't be "sorted" very well.

6 REPLIES
Acclaimed Contributor Acclaimed Contributor

Re: -mtime does not return the expected results

Hi:

 

You wrote:

 

# find . -type f -mtime +14 -exec | ls -ltr

 

...where you should have written:

 

# find . -type f -mtime +14 -exec ls -ltr {} +

 

Regards!

 

...JRF...

Honored Contributor Honored Contributor

Re: -mtime does not return the expected results

The other option you have is to do:

 

find . -type f -mtime +14 | xargs ls -ltr

Acclaimed Contributor Acclaimed Contributor

Re: -mtime does not return the expected results

[ Edited ]

>The other option you have is to do:

 

The problem with xargs is the buffer is trivially small compared to the ~1 M or so in -exec ... +.

The ll -t output will be in smaller chunks, so won't be "sorted" very well.

Advisor

Re: -mtime does not return the expected results

 

Thanks for your help, it really worked for me. ,also what is the purpose of  '+' in the end? Is there any point system, which I can offer the points for?

 

Regards

 

Advisor

Re: -mtime does not return the expected results

 

Hi Patrik,

 

Your solution is also worked!

 

Regards

 

Highlighted
Acclaimed Contributor Acclaimed Contributor

Re: -mtime does not return the expected results

>also what is the purpose of  '+' in the end?

 

There are two forms for -exec:

-exec command args ... ;       This only does one file at a time.

-exec command args ... {} +  This does as many files as will fit.

 

The latter is better because it can reduce the number of times "command" is invoked, thus saving start up costs.

But "command" must be able to take parms like: command args ... file1 file2 ...

 

>Is there any point system, which I can offer the points for?


Click on the Kudos! stars on each reply that deserves one.