views:

51

answers:

2

Hi there,

is it possible to use a the find command in some way that it will not recourse into the sub directories? e.g.

DirsRoot
  |-->SubDir1
  |    |-OtherFile1
  |-->SubDir2
  |    |-OtherFile2
  |-File1
  |-File2

And the result of something like find DirsRoot --donotrecuourse -type f will be only File1, File2 ? Anyone knows a way?

thanks!

f.

+4  A: 

I think you'll get what you want with the -maxdepth 1 option, based on your current command structure. If not, you can try looking at the man page for find.

Relevant entry (for convenience's sake):

-maxdepth levels
          Descend at most levels (a non-negative integer) levels of direc-
          tories below the command line arguments.   `-maxdepth  0'  means
          only  apply the tests and actions to the command line arguments.

Your options basically are:

find DirsRoot/* -maxdepth 0 -type f #This does not show hidden files

Or:

find DirsRoot/ -maxdepth 1 -type f #This does show hidden files
eldarerathis
For the OP's example I think this needs to be `-maxdepth 1` ?
Paul R
@Paul R: Actually, that sort of depends on how he wants to handle hidden files, but I've amended my answer nonetheless. For his example `1` is probably what he wants.
eldarerathis
+2  A: 

I believe you are looking for -maxdepth 0.

waffle paradox
For the OP's example I think this needs to be `-maxdepth 1` ?
Paul R
Yes, if he were using the command exactly as in his example then it would be 1. My mistake.
waffle paradox