Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find command : maxdepth and mindepth usage

Status
Not open for further replies.

weirdcpu

IS-IT--Management
Mar 19, 2005
22
0
0
FR
Hello,

I try to select some files in a repertory using -newer .

if i use this kind of options it works fine :

find . -newer file_mark -print | less

BUT if i use the exec option , it doesn't work anymore :

find . -newer file_mark -exec ls -l {} \;
It print the entire directory not only the files newer than file_mark.

What i understand is that find take into account the ".." and "." entry.

So i add -maxdepth 1 and -mindepth 1 options :

find . -newer file_mark -maxdepth 1 -mindepth 1 -exec ls -l {} \;
It work fine but i don't understand why.

More work show that i need only -mindepth to have the correct files selected.

Can someone show me some information about the meening of maxdepth and mindepth ? I work in french, with gnu find and don't understand the information about -maxdepth and -mindepth within the man of find ?
 
as possible workarounds:

use [tt]-type f[/tt] in addition to the [tt]-newer file_mark[/tt], so as not to "find" the dirs.

or

use [tt]-exec ls -l[red]d[/red] {} \;[/tt] so as just to list the dirs, not their contents...

I'll look into the min/maxdepth explanations later.


HTH,

p5wizard
 
Thanks for your reply ,

but -ls -l after -exec is just here as an example that i use to verify my syntax in using find.

as i will try to generate the find command in a perl script i try not to use multiple logical condition. It will be much simple to generate the find command in a script if i can just add the options of the find sequentially in the end of a string :

Something like this :
$find_cde_string = map ( '.', @cde_option);

if i have to use some logical conditions i will must coordinate the left and right parenthesis and the fonctional instruction will not be sufficient.

 
no need to add any operator or parentheses

find /your/dir -type f -newer file_mark -exec whatever {} \;

the AND is the default operator.

So this executes your command on every FILE (not DIR or whatever else) newer than the file file_mark


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top