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

I'm trying to execute the following command: find . -name ".[ch]" | xargs grep -in pattern > file

There are some errors that are printed on stderr because a few files are not found. How can I redirect stdout to a file and stderr to /dev/null/ in the same command?

This command didn't work: find . -name ".[ch]" | xargs grep -in pattern 1> file 2> /dev/null/

The error message: ksh: /dev/null/: cannot create [Is a directory]

Can anyone tell me how I can do this?

Cheers, VSN

share|improve this question
up vote 3 down vote accepted

You typed /dev/null/ where it should be /dev/null !

find . -name ".[ch]" | xargs grep -in pattern 1> file 2> /dev/null

should work...

share|improve this answer
I feel really silly. Yeah, that worked... 0_0 Thanks a lot, sincerely! :) – VSN Nov 19 '12 at 13:41
This kind of things happens even to the best ones among us. :) Happy I could help you. – Orabîg Nov 19 '12 at 13:43

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.