find without recursion
Is it possible to use the find
command in some way that it will not recurse into the sub-directories? For example,
DirsRoot
|-->SubDir1
| |-OtherFile1
|-->SubDir2
| |-OtherFile2
|-File1
|-File2
And the result of something like find DirsRoot --do-not-recurse -type f
will be only File1, File2
?
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:
# Do NOT show hidden files (beginning with ".", i.e., .*):
find DirsRoot/* -maxdepth 0 -type f
Or:
# DO show hidden files:
find DirsRoot/ -maxdepth 1 -type f
I believe you are looking for -maxdepth 1
.
If you look for POSIX compliant solution:
cd DirsRoot && find . -type f -print -o -name . -o -prune
-maxdepth is not POSIX compliant option.
Yes it is possible by using -maxdepth option in find command
find /DirsRoot/* -maxdepth 1 -type f
From the manual
man find
-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the starting-points.
-maxdepth 0
means only apply the tests and actions to the starting-points themselves.