Find all files matching a given pattern AND excluding a given pattern? Find all files matching a given pattern AND excluding a given pattern? unix unix

Find all files matching a given pattern AND excluding a given pattern?


You can use find . -name "pattern" and then add a negative condition for the pattern you don't want to have:

find . -name "pattern_A" ! -name "pattern_B"

Example

Let's look for those files whose name contains a A but not a B:

$ ls -1adfadAadsaadfBasdAAksjdflksjasdfBasdfBadsf$ find . -name "*A*" ! -name "*B*"./Aksjdflksj./adfadAadsa