5.12. Redirecting Background ProcessesTo prevent the output from a background process from arriving at your terminal, redirect its output to a file. In the following example, I redirected the standard output of the find command to a file called "find.txt". As the command was executing, I watched it grow using the ls command: $ find . -name a.c -print > find.txt & 27188 ...process ID of "find". $ ls -lG find.txt ...look at "find.txt". -rw-r--r-- 1 glass 0 Feb 3 18:11 find.txt $ ls -lG find.txt ...watch it grow. -rw-r--r-- 1 glass 29 Feb 3 18:11 find.txt $ cat find.txt ...list "find.txt". ./wild/a.c ./reverse/tmp/a.c $ _ Another alternative is to mail it to yourself: $ find . -name a.c -print | mail glass & 27193 $ gcc program.c ...do other useful work. $ mail ...read my mail. Mail version 8.1 6/6/93. Type ? for help. >N 1 glass@utdallas.edu Mon Feb 3 18:12 10/346 & 1 From: Graham Glass <glass@utdallas.edu> To: glass@utdallas.edu ./wild/a.c ...the output from "find". ./reverse/tmp/a.c & q $ _ Some utilities also produce output on the standard error channel, which must be redirected in addition to standard output. The next chapter describes in detail how this is done, but I'll supply an example in Bash and the Korn shell now, just in case you're interested: $ man ps > ps.txt & ...save documentation in background. 27203 $ Reformatting page. Wait ...shell prompt comes here. done ...standard error messages. man ps > ps.txt 2>&1 & ...redirect error channel too. 27212 $ _ ...all output is redirected. |