Piping in Linux Operating System
Piping in Linux Operating System
Piping in Linux (or Unix-like systems) is a powerful feature that allows the output of one command to be used as the input for another command. It is done using the pipe operator symbol (|).
Piping in Linux
Piping is the process of sending the output of one command to the input of another command. Let’s see an example below of piping two commands in Linux.
When you use a pipe (|), it connects two commands in such a way that the output of the first command is passed directly into the second command for further processing.
ps command
ps command allows us to list the processes running in the Linux box. We can use ps -aef command to output all the processes running on the system.
$> ps -aef
to know more about the ps command, we can use
$> man ps
However, let’s say we are interested in only the processes that run firefox we can pipe the ps output to a search command like grep . grep command is used to search for keywords. It searches for the pattern specified. There are several variations of this command like grep,fgrep, etc. To know more or learn about the commands, type the below command
$> man grep
To use the pipe command, redirect the output of the ps command to the grep command as shown below:
$> ps -aef  | grep firefox
Example with multiple pipes
$ ps aux | grep “Python” | wc -l
- “ps aux” lists all running processes.
- grep “Python” filters the processes to only those related to Python.
- wc -l counts the number of Python-related processes.
Pipes help to create flexible, efficient workflows in the terminal.