• Wincent
    Open
  • Blog
  • Wiki
  • Snippets
  • Tags
  • Search

Finding files which do not contain a given stringEdit

Created 7/10/2011, updated 3/12/2020

While finding files containing a string is easy with grep, it is non-obvious how to do the opposite and list files which do not contain a given string.

Here’s an example, listing all files in the current directory which do not contain the string "ActiveRecord::Base":

$ find . -type f ! -exec grep -q ActiveRecord::Base {} \; -print
  • find
  • grep
  • wiki
Site
  • About
  • Blog
  • Wiki
  • Snippets
  • Tags
  • Search
External
  • GitHub
  • Twitter
  • YouTube
  • Facebook
  • LinkedIn
Colophon

Made by Greg Hurrell using React, Relay and GraphQL (with help from Git, Redis and Neovim).