Pipes in Linux, represented by the vertical bar symbol |, are a fundamental feature that allows you to redirect the output of one command to the input of another.
pipes in Linux and redirect the contents returned by a command to another file
When you connect two or more commands with a pipe, the standard output (stdout) of the first command is not displayed on the screen, but becomes the standard input (stdin) of the next. This process can be chained multiple times, creating a command pipeline.
an example for you to understand:
List the files and save the output to a temporary file:
ls -l > file.txt
Count the lines of the result:
wc -l
With pipes, everything is done in a single command line, without the need for temporary files:
ls -l > file.txt | wc -l
an example in an image:

Pipes are incredibly useful for filtering, sorting, and manipulating text data. Some of the most common uses include:
- Filter data: Combine grep with the output of another command to find specific information. For example, ps aux | grep firefox shows you running Firefox processes.
- Sorting results: Use sort to sort the output. For example, ls -l | sort -r sorts the files in a directory in reverse order.
- Count lines or words: Use wc to count items. For example, cat file.txt | wc -l counts the lines in a file.
- Combine with other commands: Redirect output to more complex programs like awk or sed to perform more advanced manipulations.
another example:
curl -H "Authorization: Bearer TOKEN" 'https://api.web.com/endpoint' | jq . > file
This sorts the output of the API with jq and sends the content to a file called “file” with “>“
then you can see the content of file and it will be a neat JSON with jq
You can see the contents of “file” with the cat command
cat file