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


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

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

should work...

  • 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 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.