About.com: Using pipes in Linux | Linux Today

About.com: Using pipes in Linux

Written By
Web Webster
Web Webster
Oct 14, 2000

“If you’re a novice shell user, you’ve probably heard of pipes
but don’t really know what they are or how to use them. A pipe
is a special line of communication opened by the shell between one
program’s output and another program’s input.
In the shell, a
pipe is represented by the vertical bar (|) character.”

“To connect a command’s output to another command’s input using
a pipe, place a vertical bar between the two commands. For example,
to get a directory listing but send it to the printer instead of to
the display, try:

  $ ls -1 | lpr

In this case, the output of the ls command goes to the the lpr
command, which uses it as input and sends it to the printer.”

“Sometimes, very complex tasks can be performed by
connecting long strings of pipes together
:

  $ ls -1 | grep txt | grep -v jake | cut -d. -f1 | sort | lpr

This series of commands first gets a list of files in the current
directory with ls. This list is sent to the grep command, which
searches for the text “txt” in the filenames. The list of filenames
containing the word “txt” is then sent to the grep command again,
this time to filter out any names containing the text “jake” from
the list. This shortened list is then sent to the cut command,
which removes all “extensions” from the filenames. The list is now
sent to sort, which rearranges the list into alphabetical order
before finally sending it to lpr which will send the list to the
printer. Whew!”


Complete Story

Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.