1830234 Members
2392 Online
109999 Solutions
New Discussion

find command

 
SOLVED
Go to solution
Victor_5
Trusted Contributor

find command

I only want to list the files of April, when I run

find . -atime -17 -exec ls -al {} \;

It returned everything not only April but also Jan. Feb...., what is the correct command to find those files only in April?
11 REPLIES 11
Helen French
Honored Contributor

Re: find command

Hi Victor:

Use '-mtime' option:

# find . -mtime -17 -exec ls -al {} \;

HTH,
Shiju

Life is a promise, fulfill it!
Darrell Allen
Honored Contributor
Solution

Re: find command

Hi Victor,

Use reference files and "newer" logic:

touch 03312359 /tmp/Mar
touch 05010000 /tmp/May
find . -type f -newer /tmp/Mar -a ! -newer /tmp/May

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Mark van Hassel
Respected Contributor

Re: find command

Hi,

atime means acces time. You should try mtime (file modification time).

HtH,

Mark
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us
S.K. Chan
Honored Contributor

Re: find command

You can do thie .. create a dummy reference file dated April 01 00:01 and use find command to list all files newer than that reference file.
Eg : in /opt

# cd /opt
# touch 04010001 ref-file
# find . -newer ref-file -exec ls -al {} \;

A. Clay Stephenson
Acclaimed Contributor

Re: find command

Hi:

The find command is returning just what you asked. Find all the files that have been ACCESSED (-atime) in the past 17 days butr the ls command is displaying the modification times. It is entirely possible that a file has been recently accessed but last modified months ago. You probably want to use the find -mtime argument instead.

If it ain't broke, I can fix that.
Darrell Allen
Honored Contributor

Re: find command

Hi again,

Should have said that you don't need the "-a ! -newer May" if you are checking for the current month"

find . -type f -newer /tmp/Mar

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
John Palmer
Honored Contributor

Re: find command

It could also be that you are listing the contents of directories that have been selected by find.

If you are only interested in files then supply '-type f' to find or you could suppress the listing of the contents of directories with 'ls -ald {}'

Regards,
John
Carlos Fernandez Riera
Honored Contributor

Re: find command

ll -R | grep " Apr " should be enough.


There is not reason to do a find followed to ll.

unsupported
pap
Respected Contributor

Re: find command

Hi USe,

-mtime instead of -atime.

-atime is for accessed files for a particular period of time. This is the reason you are getting all files in your find result which you run the command.

-pap
"Winners don't do different things , they do things differently"
Catherine_3
Occasional Advisor

Re: find command

Hi Victor ,
I think Chan's method can work.

I have a test

You can do thie .. create a dummy reference file dated April 01 00:01 and use find command to list all files newer than that reference file.

#cd /
# touch 04010001 ref-file
# find . -newermm ref-file -print
note m - modified
or
#cd /
# touch 04010001 ref-file
# find . -newermm ref-file -print

try it

Victor_5
Trusted Contributor

Re: find command

I missed on switch, -type f, no matter I use -atime -mtime or even -ctime, the output was same, the final command is

find . -type -f -mtime -17 -exec ls -al {} \;

-newer also can work.

Carlos, I like you idea, thanks!

Catherine, thanks a lot!

Thank you, all!