Search code examples
bashfilenames

Finding all filenames with containing 1 string but not containing another string


I am trying to list all file names that contain a certain string but do not contain another string. For this particular case, I want all filenames containing "*.java" but not "*Test.java". To find and save the first set, I was using:

find -name "*.java" > sources.txt

But I don't know how to exclude the files that contain "*Test.java" in the file name. I'm new to bash, so sorry if I've missed something obvious.


Solution

  • You can use:

    find -name "*.java" ! -name "Test.java"