5

I've been trying to learn how to use apt-get in Ubuntu and I came across this command on a how to geek article

sudo dpkg –list | less

So this basically lets us look at a list of packages we have installed in our machine and "scroll through the list"

My Question in is, what is the | charactere there? Right before less, What is it's purpose, I'm just trying to understand the syntax of the command. Why isn't it just another option, like -less?

  • See askubuntu.com/q/172982/295286 It's called pipe. Really important and one of the most useful features of command line – Sergiy Kolodyazhnyy May 27 '17 at 14:25
  • 1
    Let me grab the occasion to mention MS-DOS also supported the same pipe but since it was a single task OS, it buffered the output of the first program and when it finished then it handed it over to the second while in Unix -- which is multitasking -- the second program can process the output of the first while the first produces more output. – chx May 27 '17 at 15:41
5

The | also known as pipe.

Pipe is used to take the output to use in another command.

For example when we you use this command echo "ubuntu" | grep u, the output of echo "ubuntu" is sent to grep program.

6

| is called pipe. The pipe operator passes the output of one command as input to another. A command built from the pipe operator is called a pipeline.

In UNIX like operating systems, a pipeline is a sequence of processes chained together by their standard streams, so that the output of each process feeds directly as input to the next one.

Suppose, you have $ command 1 | command 2 | command 3, then

enter image description here

Source: Using Pipes with Linux Commands

For example, if you want to list all files in a folder, you will probably use the following:

$ ls -la

Now, suppose, you want to list only java source files, you would probably do something a follows:

$ ls -la | grep .java

ls -la produces a process, the output of which is piped to the input of the process for grep .java.

You can learn more about pipes and filters here.

2

| is an operator called Pipe:

When you need the output from command 1 for the input into command 2, then you would use pipe character '|'. Here is the syntax for the pipe character:

command | command

Example:

rahul@VM:~$ ls | sort
Desktop
Documents
Downloads
examples.desktop
Music
Pictures
Public
Templates
Videos

The above example is using the output from ls as input to the sort command. You will notice the list has been sorted.

As you can see, the command line is an easy and powerful way of completing many tasks

Ref:https://help.ubuntu.com/community/CommandlineHowto

  • Your title says "The Command is called pipe". Pipe is not a command. It's an operator. There's a significant difference. – Sergiy Kolodyazhnyy May 27 '17 at 16:04
  • @SergiyKolodyazhnyy: Ohh yeah. Thanks for pointing out. – Rahul May 27 '17 at 17:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.