Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

The Linux Pipe Command

Connect commands with the | symbol so the output of one becomes the input of the next.

How-To Guides2 min read4 steps2 screenshots

What is a pipe

The pipe | sends the output of one command straight into another command. You can build small tools into powerful ones without temporary files.

How it works

  1. Run the first command. It produces some output.
  2. Add the pipe. Type | after the first command.
  3. Run the second command. It reads the output of the first as input.
  4. Repeat. You can chain as many commands as you need.

Basic examples

List only the .txt files:

ls | grep ".txt"
Filtering the ls output with grep

Search a file for a word:

cat myfile.txt | grep "keyword"
Searching file content with grep

(grep "keyword" myfile.txt gives the same result.)

More ways to use pipes

  • Transform data. Sort, cut and count the output.
  • Control the next step. Use the output to decide what to do.
  • Process files. Automate copying, moving or renaming.
  • Build scripts. Combine simple commands in one line.

Chain several commands

cat log.txt | grep "error" | sort -k 1 | cut -d " " -f 2-

This reads the log, keeps the lines with "error", sorts them by the first field and prints everything from the second field.

Other useful examples

Count the files in a folder:

ls | wc -l

Show the 5 biggest folders:

du -sh * | sort -rh | head -5

Find a running process:

ps aux | grep nginx

Scroll long output:

dmesg | less

Save and show output at once:

ls -l | tee list.txt

Why use pipes

  • Simple. Each command does one job well.
  • Fast. Data flows in memory, no temporary files.
  • Flexible. You can combine any commands.
  • Easy to read when you keep the chain short.

Quick recap

  • command1 | command2 feeds the output of the first into the second.
  • Chain many commands, one idea at a time.