Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find without recursion

Tags:

find

shell

unix

People also ask

Is the find command recursive?

Use the find command to recursively search the directory tree for each specified Path, seeking files that match a Boolean expression written using the terms given in the following text. The output from the find command depends on the terms specified by the Expression parameter.

What is recursive search Linux?

It is a versatile pattern that invokes grep with –r. –R option search files recursively from subdirectories, starting from the current directory. The command is run from the top-level directory. For instance /home/abc etc. Grep is a tool for obtaining dependencies while moving from one host to another.

How do I search for only files in Linux?

Open the command-line shell and write the 'ls” command to list only directories. The output will show only the directories but not the files. To show the list of all files and folders in a Linux system, try the “ls” command along with the flag '-a” as shown below.


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.