If you can see this check that

next section            up prev page next page

Using Pipes

You have seen how to use the > symbol to redirect output from standard output to a named file, and you have used the >> symbol to redirect output and append it to a named file without overwriting that file. However, by using what is termed a pipe, output from one command can be sent directly to another command as input. A pipe can link any two programs, provided the first program writes its output to stdout and the second program reads its input from stdin. The pipe symbol is represented as a (|). Its general syntax is as follows:

command1 | command2

command1 is the first command in the pipeline whose output is piped through the | symbol as input to command2. For example, suppose you want to know how many lines 2 of your file contain when combined together. You could do the following:

% cat file1 file2 > sample_file
% wc -l < sample_file
121
With a pipeline, these two commands can be combined into a single line:
% cat file1 file2 | wc -l
121

As we can see, using pipes eliminates the need for temporary intermediate files. Pipes can be used in many instances. For example, the following command would send a long listing of your directory to the printer.

% ls -l | lpr


Centos 7 intro: Paths | BasicShell | Search
Linux tutorials: intro1 intro2 wildcard permission pipe vi essential admin net SELinux1 SELinux2 fwall DNS diag Apache1 Apache2 log Mail
Caine 10.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam |
CPD: Cygwin | Paths | Files and head/tail | Find and regex | Sort | Log Analysis
Kali: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7a | 8a | 8b | 9 | 10 |
Kali 2020-4: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10 |
Useful: Quiz | Forums | Privacy Policy | Terms and Conditions

Linuxzoo created by Gordon Russell.
@ Copyright 2004-2023 Edinburgh Napier University