Piping

Piping is one of the most powerful features of the Linux command line. It allows you to take the output of one command and send it directly into the input of another command.

The Pipe Operator (|)

The pipe character | acts as a conduit between two commands.

Bash

command1 | command2

Why use Piping?

Following the Unix Philosophy, Linux has many small tools that do one thing well. By piping them together, you can perform very complex tasks without writing any complex code.

Common Piping Examples

1. ls | grep

Search for a specific file in a long list:

Bash

ls /usr/bin | grep python

2. cat | wc

Count the number of lines in a specific file:

Bash

cat names.txt | wc -l

3. ls | head

See only the first 5 files in a directory:

Bash

ls -l | head -n 5

Note: You can chain as many commands as you want!
Example:ls | grep ".txt" | wc -l (Count how many .txt files are in the directory).