Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a bunch of files in a folder:

foo_1 
foo_2
foo_3
bar_1
bar_2
buzz_1
...

I want to find all the files that do not start with a given prefix and save the list to a text file. Here is an example for the files that do have a given prefix:

find bar_* > Positives.txt
like image 533
Robert Avatar asked Jan 26 '14 20:01

Robert


1 Answers

If you're doing subdirectories as well:

find . ! -name "bar_*"

Or, equivalently,

find . -not -name "*bar_*"
like image 58
lurker Avatar answered Oct 05 '22 04:10

lurker