Some single commands actually spawn multiple processes.
On UNIX systems, you can apply the output of one command as the input to another, without creating an intermediary temporary file. We say that the output of one program is piped through another program (sometimes called a filter).
For example, suppose I want to search for all users logged in today who stayed logged in overnight. The who command shows me user names and what day they logged in:
% who tanya console Oct 19 09:30 lmui ttyp0 Oct 18 15:58 (opal:0.0) sybase ttyp1 Oct 18 16:01 (rock.west.ora.co) mam ttyp2 Oct 19 13:03 (ncd12.ora.com:0.) val ttyp4 Oct 12 18:22 (harry.ora.com:0.) ...
Today is October 19. I might save this output in a file and then use the -v option to the grep command to search for all lines that do not have “Oct 19.” So here’s one way I might do what I want using two commands and one temporary file:
% who > who.out % grep -v "Oct 19" who.out lmui ttyp0 Oct 18 15:58 (opal:0.0) sybase ttyp1 Oct 18 16:01 (rock.west.ora.co) val ttyp4 Oct 12 18:22 (harry.ora.com:0.) ...
But I could also do this using one command and no temporary files, by just piping the output of who directly through the grep command.
% who | grep -v "Oct 19" lmui ttyp0 Oct 18 15:58 (opal:0.0) sybase ttyp1 Oct 18 16:01 (rock.west.ora.co) val ttyp4 Oct 12 18:22 (harry.ora.com:0.) ...
The advantage here is that it’s faster, and that it doesn’t require creating a temporary file that you then have to remove. However, it also means that you’re running ...
Get WYNTK: UNIX System Admininistrator now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.