Pipelining is a very powerful feature that allows you to send the output of one command as the input to another.
The notation used is a vertical bar
$ ls /usr/bin | less
The output of the
ls /usr/bin command will be passed in as an argument to the command on the right. Thus, we will be able to view the contents in our bin file through the
less file reader.
We can have multiple pipes, which makes pipelineing not only useful, but fun!
To sort the outputs alphabetically, use the
$ ls .. | sort
To grab just the unique names of within a file, we can use
$ cat employeeNames.txt | sort | uniq
To find text patterns, we can use
grep, followed by a string.
Grep actually stands for "global expression pattern." If you know regex, you can use regex syntax to capture a specific string pattern.
$ ls .. | grep .html
This would return all outputs that have the .html extention in them.
To check the number of lines, words and bytes in a file, we can use the
$ less fileName.txt | wc
5 7 61
This means we have 5 lines, 7 words and 61 bytes.
We can use the
tee command to output to standard out as well as a file. In this way, we can save the results of our pipeline.
$ ls /usr/bin | tee test.txt | grep zip
This command lists all files in /usr/bin, sending it off to the next pipe, then writes it to test.txt.
Remember to check each command's man page to learn more options!
$ man sort
In this completely revised second edition of the perennial best seller How Linux Works, author Brian Ward makes the concepts behind Linux internals accessible to anyone curious about the inner workings of the operating system. Inside, you'll find the kind of knowledge that normally comes from years of experience doing things the hard way.$ Check price
Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.$ Check price