I'm new to shell scripting and I want to know what the difference is between pipe and filter. They both seem to do the same things. Even the format is the same.
ls -l | grep user |cat >user
A pipe or a filter?
The graph below briefly describes the relationship of pipe, filter, pipeline and redirection.

Filter is only one ELEMENT of a pipeline, all the elements in pipeline are collected by pipe. Below is the definition of Filter in Wikipedia.
In Unix and Unix-like operating systems, a filter is a program that gets most of its data from its standard input (the main input stream) and writes its main results to its standard output (the main output stream). Unix filters are often used as elements of pipelines. The pipe operator ("|") on a command line signifies that the main output of the command to the left is passed as main input to the command on the right.
In your example, the whole command is a pipeline:
ls -l | grep user | cat > user
ls is acting as the source of data. grep is then acting as a filter - a filter performs some kind of transformation on the data. The pipe (|) passes the data from ls to grep, performing buffering etc. Finally cat (which is extraneous in your example) outputs the filtered data to something (terminal, file, variable).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With