Is there a way to prevent a search from recursive search into subdirectories?

When I do this:

$ find / 

He is looking for the whole system.
How to prevent this?

(This question is based on the answer to another question.)

+3
source share
5 answers

G'day

Just wanted to expand John's suggestion to use -prune. This is not the easiest way to search, for example, to search in the current directory, the find command looks like this:

find . \( -type d ! -name . -prune \) -o \( <the bit you want to look for> \)

this will stop the descending search in subdirectories in this directory.

Basically, he says, "truncate everything that is a directory whose name is not specified.", That is, the current directory.

find evals , , , , -o (OR'd) .

.

, Rob

+4

:

-maxdepth n
             True if the depth of the current file into the tree is less than
             or equal to n.

-mindepth n
             True if the depth of the current file into the tree is greater
             than or equal to n.
+9

. , ksh :

$ ls *.ksh
+3

-prune.

0

echo /specific/dir/*.jpg

, . Typing

ls *.jpg

ls foo.jpg bar.jpg

foo.jpg bar.jpg - , ".jpg" .

0

Source: https://habr.com/ru/post/1696533/


All Articles