GNU Search: Search the current directory first

how can I say what to find first search in the current folder and then continue searching in subfolders? I have the following:

$ find . -iname '.note'
folder/1/.note
folder/2/.note
folder/3/.note
folder/.note

I want it:

$ find . -iname '.note'
folder/.note
folder/1/.note
folder/2/.note
folder/3/.note

Any ideas?

+3
source share
5 answers

find the algorithm is as follows:

  • For each path specified on the command line, let the current record be this way, and then:
    • Match the current record with the expression.
    • If the current entry is a directory, follow steps 1 and 2 for each entry in this directory in the unspecified order.

With -depthprimary, steps 1 and 2 are performed in reverse order.

, find, 2. find .

, find . -iname '.note' | sort . , , .

- find (, find ) .

find -type d -exec print-matching-files-in {} \;

find , find - , ( GNU):

find -type d -exec find {} -maxdepth 1 \! -type d … \;

:

find -type d -exec find {} -maxdepth 1 \! -type d -iname '.note' \;

zsh

print -l **/(#i).note(Od)

**/ ; (#i) (a ) , , (Od) (a glob qualifier) , . (Odon) , Od (.. ).

+3

find . -iname '.note' | sort -r:

$ find . -iname '.note' | sort -r
folder/.note
folder/3/.note
folder/2/.note
folder/1/.note

.

+1

GNU find Linux .

TestCase:

rm -rf /tmp/depthtest ; mkdir -p /tmp/depthtest ; cd /tmp/depthtest ; for dir in 1 2 3 . ; do mkdir -p $dir ; touch $dir/.note ; done ; find . -iname '.note'

. 1 2 3 .. . 1 2 3

rm -rf /tmp/depthtest ; mkdir -p /tmp/depthtest ; cd /tmp/depthtest ; for dir in . 1 2 3 ; do mkdir -p $dir ; touch $dir/.note ; done ; find . -iname '.note'

.

-depth .

:

perl oneliner, :

perl -e 'opendir(DH,".") ; print join("\n", readdir(DH)),"\n" ; closedir(DH)'

/tmp/depthtest 1 :

.
..
1
2
3
.note

2 :

.
..
.note
1
2
3

, .

-depth , , ./1/.note ./1/, ./.note . /1/, ( ).

, , ?, , .

+1

find -s . -iname ".note" ? find . -iname '.note'|sort?

0
source

Find in current folder

 find ./in_save/ -type f -maxdepth 1| more

==> 73

0
source

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


All Articles