Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

At the moment I'm using two commands, I'm sure there must be a better way...

wim@wim-acer:~/ffmpeg$ find . -name "*.h" -print0 | xargs -0 grep -i invalid\ preset
wim@wim-acer:~/ffmpeg$ find . -name "*.c" -print0 | xargs -0 grep -i invalid\ preset
share|improve this question
does -name '*.[ch]' work? – glenn jackman Aug 25 '11 at 14:40
up vote 9 down vote accepted

ack (or, on Debian/Ubuntu, ack-grep) will ignore non-source files like version control or binaries. Very useful.

to search just .c and .h files, as above:

ack-grep -i --cc "invalid preset"

the --cc (the longer form is --type cc) only looks at .c .h & .xs files. The full list of filetypes is viewable with ack-grep --help type. Most of the time, you won't particularly need the --type, as it will generally only have the files to search, and then files you won't see by default, like binaries, backups and version control files.

share|improve this answer
thanks.. i've installed it, but the interface is unfamiliar.. can you please give an example usage equivalent to what i had above? – wim Aug 25 '11 at 8:33
thanks.. my problem was i went sudo apt-get install ack instead of sudo apt-get install ack-grep. ack was a japanese character converter, no wonder i was so confused trying to get it to grep! – wim Aug 26 '11 at 0:27

The grep program itself can search recursively and also accepts an option to search only certain files. The following is equivalent to your two find commands.

grep -Ri --include=*.[ch] invalid\ preset .
share|improve this answer
This worked for me when I got rid of the brackets – Mike Oct 31 '15 at 22:48

The find command can call grep itself.

find . \( -name "*.c" -o -name "*.h" \) -exec grep -i "invalid preset" {} \; -print

and variations of thereof.

share|improve this answer
perhaps you misunderstood the question - this only searches in c files. – wim Aug 25 '11 at 8:32
Changed it to the obvious variation. ;-) – Keith Aug 25 '11 at 8:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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