5

I want to search my directory for "foo" in the files, but i have these gigantic sql files. How do I exclude these file types or file sizes larger than 3MB using ack-grep? Also how would this be done with grep?

  • 1
    ack foo --nosql will ignore anything with a .sql extension. To see more about the filetypes ack supports, see ack --help-types. ack has no way of filtering on file size. – Andy Lester Mar 1 '16 at 22:49
4

I don't know about ack-grep but you can use find to exclude files larger than 3MB.

find . -size -3M -exec grep "foo" {} \;
  • what does {} and the slash \ stand for in that grep command? – Patoshi パトシ Feb 29 '16 at 6:39
  • 1
    {} is the placeholder for the file names "found" by find. \; escapes the semicolon and makes it a terminal semicolon of the -exec command of find instead the shell. See man find or just google some simple tutorial on find. It's a very powerful and useful command line tool. – Munir Feb 29 '16 at 14:31
  • Use -exec grep "foo" {} + to make grep output the names of the matched files. – Nemo Feb 29 '16 at 22:38
6

According to the ack doc and man page you can ignore files with a particular extension by using --ignore-file=filter where filter is filtertype:filterargs. One of the filtertypes is ext for file extension. So try

--ignore-file=ext:sql

or since sql is one of the built-in types, you can just use

--nosql
  • 1
    To see all the file types recognizes, see ack --help-types. – Andy Lester Mar 1 '16 at 22:49

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.