I'm using ag (The Silver Searcher) version 0.31.0. I can easily look for a string in a bunch of files using:

localhost:workspace davea$ ag 'ftp' .

But what if I only want to scan files with certain extensions? I tried this:

localhost:workspace davea$ ag 'ftp' .java
ERR: Error stat()ing: .java
ERR: Error opening directory .java: No such file or directory

but got the errors you see above.

  • Gave that a whirl but got "ERR: Error stat()ing: *.java" and "ERR: Error opening directory *.java: No such file or directory" errors – Dave Feb 8 '17 at 21:22

Per the manual, you could use ag with -G

   -G --file-search-regex PATTERN
          Only search files whose names match PATTERN.


ag -G '\.java$' 'ftp' .

Per the same manual

   It is possible to restrict the types of files searched [...]
   For a list of supported types, run ag --list-file-types.

So you could also run

ag --java 'ftp' .

though that would restrict the search to file names ending in .java or .properties

  • 2
    oops sorry, deleting. – Peter Krauss Sep 17 '18 at 20:10
  • ` ag -G '\.(hbs|html)$' keyword ` if you are searching multiple file extensions – Alan Dong May 9 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.