Using the Pipe (|) in Bash

The pipe (|) in Bash is used to direct the output of one command (stdout) as the input (stdin) to another command. This allows you to combine multiple commands in powerful ways to process data efficiently.


Basic Syntax

command1 | command2

When to Use Pipes


Basic Examples

Count the number of files and directories

Use ls to list files and wc -l to count the lines of output:

ls -lhs | wc -l

Explanation: