How do I find all files that do not begin with a given prefix in bash?

If you're doing subdirectories as well:

find . ! -name "bar_*"

Or, equivalently,

find . -not -name "*bar_*"

This should do the trick in any shell

ls | grep -v '^prefix'

The -v option inverts grep's search logic, making it filter out all matches. Using grep instead of find you can use powerful regular expressions instead of the limited glob patterns.


You want to find filenames not starting with bar_*?

recursive:

find ! -name 'bar_*' > Negatives.txt

top directory:

find -maxdepth 1 ! -name 'bar_*' > Negatives.txt