The usage of pipes with the shell is easy and powerful. This lab will help you understand the use of pipes.
1. Piping to less
Using less allows you to move up and down with commands that the vi editor uses. When you have completed what you want to review, click “q” to quit.
ls -l /etc | less
This time issue a number of commands with less open.
ls /etc | less
Remember, if you issued the command ls -l the line begins with permissions and some of the searches will not work.
2. Check number of users logged in
who | wc -l
Here you are piping the command who, which shows the users logged in and sending the output into wc which will count the lines “-l” so come up with a number of users.
3. Check processes
ps aux | grep mingetty
List all processes that have the text string mingetty. The ps command with the “aux” options will show all the processes currently running whether they were started as daemons or users started them. The grep command is a great tool to search for text strings.
4. Multiple pipes
ps aux | grep mingetty | grep tty3
Pipes can be used a number of times to get output you need.