Search code examples
bashshellag

What is the best way to find all the files that do not have a match?


I have a large application and I need to find a list of files that do not contain an expression. I have been using The Silver Searcher but I am unsure how to get the opposite

Example ag 'breadcrumbs' app/controllers This gives a list of all the files and line number where I can find this expression in the controllers' directory

What I am trying to get is a list of all the files that do not have breadcrumbs

I am open to bash or shell scripts as well

Thanks for the help


Solution

  • For The Silver Searcher (ag), ag -vl breadcrumbs directory_here will do what you're looking for.

    -l lists files, and -v inverts the match to find files that don't match.

    You could also do ag -L breadcrumbs directory_here

    -L lists all files that do not contain a match.