Before diving into advanced command line usage examples, I'd like to explain another basic concept - piping. Piping is the inter-process communication mechanism that allows to send the output of one program to another program. To pipe programs together in a shell, we use the vertical bar character |. The general syntax is:
command one | command two [| command three …]
What happens when you pipe 2 programs?
The shell creates a process for each program and arranges the necessary connections between their standard streams. Basically, the stdout from the program on the left is directed to the stdin of the program on the right through a pipe.
Let's go through a simple example. We'll pipe 4 commands to find the ids of all running Google Chrome processes:
ps aux | grep "Google Chrome" | grep -v "grep" | awk '{print $2}'
To conclude, we use the |
(pipe) operator to feed the output of one program as input to another program. We can pipe multiple programs together to customize the output however we like.
Get this detailed online course and learn TypeScript and how to use it in React applications.