Pipes and subshells – your shell's salt and pepper
In this section, we will be looking at ways to improve your productivity using your shell. The Linux command line is great because it has a variety of tools we can use. What makes it even greater is the fact that we can chain these tools together to form greater, more powerful tools that will make us even more productive. We will not go into basic shell commands; instead we will be looking at some cool pipe and subshell combinations that can make our lives easier.
Let's start with a basic pipe; in this example, we are counting the length of the current path using the following command:
pwd | wc -c
pwd,
as you probably know, stands for print working directory
. The |
is the pipe symbol, and what it does is send the output of the command on the left to the command on the right. In our case, pwd
is sending its output to wc -c
, which counts the number of characters. The coolest thing about pipes is that you can create a chain...