Linux pipe tutorial

Linux pipe operator, which is the | symbol offers great benefits when working in Linux command line terminal. It can be used to combine Linux commands and manipulate the command output. Maybe you start thinking that it is a bit advanced for a new user who just learned a few Linux commands and better skip learning it now because it's not very helping for a Linux beginner. Believe me, the sooner you learn it, the more you'll benefits from it.

This tutorial will introduce a very basic Linux pipe usage so that a new user can start using it while learning Linux basic commands.

Let's see the first example on how to use pipe to combine Linux command and manipulate the command's output.

[email protected]:~$ ls /etc/ | grep
[email protected]:~$

In the example above, we use ls command to view content of /etc directory. Because the /etc directory has many files and directories, we use Linux pipe (|) to send the output to the next command which is the grep command to grab term that we want (

Here is another example of how to manipulate command's output using Linux pipe to send it to another command:

[email protected]:~$ dmesg | less
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 2.6.27-14-generic ([email protected]) (gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu11) )
#1 SMP Tue Jun 30 19:57:39 UTC 2009 (Ubuntu 2.6.27-14.35-generic)
[ 0.000000] BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: 0000000000000000 - 000000000009f800 (usable)
[ 0.000000] BIOS-e820: 000000000009f800 - 00000000000a0000 (reserved)
[ 0.000000] BIOS-e820: 00000000000dc000 - 0000000000100000 (reserved)
[ 0.000000] BIOS-e820: 0000000000100000 - 000000001f680000 (usable)
[ 0.000000] BIOS-e820: 000000001f680000 - 000000001f700000 (ACPI NVS)
[ 0.000000] BIOS-e820: 000000001f700000 - 0000000020000000 (reserved)
[ 0.000000] BIOS-e820: 00000000e0000000 - 00000000f0000000 (reserved)
[ 0.000000] BIOS-e820: 00000000fec00000 - 00000000fec10000 (reserved)
[ 0.000000] BIOS-e820: 00000000fed00000 - 00000000fed00400 (reserved)
[ 0.000000] BIOS-e820: 00000000fed14000 - 00000000fed1a000 (reserved)
[ 0.000000] BIOS-e820: 00000000fed1c000 - 00000000fed90000 (reserved)
[ 0.000000] BIOS-e820: 00000000fee00000 - 00000000fee01000 (reserved)
[ 0.000000] BIOS-e820: 00000000ff000000 - 0000000100000000 (reserved)
[ 0.000000] DMI present.
[ 0.000000] last_pfn = 0x1f680 max_arch_pfn = 0x100000
[ 0.000000] kernel direct mapping tables up to 1f680000 @ 7000-d000
[ 0.000000] RAMDISK: 1ee9c000 - 1f66fa50

We use dmesg command in the example above to view Linux bootup messages. To let us read the message line by line, we use Linux pipe to pass the dmesg output to the less command.

Those are two examples of Linux pipe which has been used regularly by Linux users especially system administrators when working in Linux command line terminal. It'll be a great help for Linux new user to learn Linux and explore Linux file system for sure.

Back to Linux basic commands main page.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.