I have a huge folder with a lot of subfolders where I would like to search for a folder that contains three words. Note that the folder name needs to have all three words, but the order of the words does not matter.
Example: I want to find folders containing the words APE
, Banana
and Tree
.
find folder -name '*APE*Banana*Tree*'
However, this command will consider the order of the words, while this is not of interest and I want to find any folder with those words in any order.
Best Answer
Just use 3
-name
s:Beware that like any time you use wildcards in the
-name
pattern that it may miss files whose name contains sequence of characters not forming valid characters in the user's locale.With
zsh
:With
ksh93
:With
bash
:Where:
D
,FIGNORE
,dotglob
makes sure hidden files are also reported (likefind
does)N
,~(N)
,nullglob
makes the glob expand to nothing instead of causing an error or expand to itself when there's no matchglobstar
makesksh93
/bash
understand zsh's**/
recursive globbing operator.(x~^Y)
,@(X&Y)
,!(!(X)|!(Y))
being three approaches in the respective shells to match files that match both patterns.