6

Possible Duplicate:
Is there a way in bash to redirect output and still have it go to stdout?

Let's say I do:

ps -ef | grep httpd

to see if apache is running or not, but I also want to "dump" the output of ps -ef into a file at the same time. Like this:

ps -ef  --- grep http
       |
        --- > file

Is it possible to fork STDOUT in parallel like this? The above is only an example so little hacks like dumping to the file and then grepping the file isn't what I'm looking for.

nopcorn
  • 9,559

1 Answers1

4

Sure. You are looking for tee not fork():

ps -ef | tee file | grep http
Caleb
  • 70,105
  • Oh that's what tee does! I've only come in contact with it a couple times but thanks for clearing that up. Does it work for the other standard streams? – nopcorn Aug 26 '11 at 20:53
  • 1
    @MaxMackie: It works on whatever it is given. Unless you specifically tell the shell otherwise it will only receive the STDOUT of the proper being piped to it. – Caleb Aug 26 '11 at 20:56