Welcome to the Linux Foundation Forum!

Difference between | and ; while typing commands on prompt

mohdjsbms Posts: 1
edited May 2017 in New to Linux

When I started learning Linux from EDX courses, | (pipeline) is the first few things that are taught to me. From what I understand, pipeline allows subsequent commands to be executed co-currently with the previous commands (i.e., commands before the pipeline).

Much later, I am taught to use ; (semi-colon) as a means to "combine several commands and statements and even conditionally execute them based on the behavior of operators used in between them. This method is called chaining of commands." Does this mean that semi-colon allows subsequent execution of commands provided that the previous one is already completed?

My questions are - (1) What is the major difference between '|' and ';', and (2) when should we use either of the characters? Can both of them be used together in the same chain of commands?


  • saqman2060
    saqman2060 Posts: 777
    edited May 2017

    From what I Iearned, the "|" command allows the user to use the output from the previous commands as the "argument" for the second command. For instance, if I were to run "ls" on the current directory "/home" I would get a list of everything in the directory. If I wanted to find a certain value from that directory or "print out" a particular value, then I would use "grep" on the previous output and search for a particular pattern. Example:

    ls /usr/bin | grep firefox

    The above command will print out everything in the /usr/bin directory and send that output to grep(the output of "ls" is not shown when doing this) which tells grep to read the invisible output from "ls" and find a file named "firefox". If grep finds firefox, the file firefox will be the only valued printed in the terminal.

    The ";" character allows the user to run more than one command. This is no different then just putting a space inbetween the commands. using the ";" the first command does not have to complete successfully for the other commands to run. You are just trying to do everything in one line.

    Hope this helps clear some things up

  • ChristianC123
    ChristianC123 Posts: 1
    edited May 2017

    PIPE "|" used to combine 2 or more Commmands  

    • Pipes '|' help combine 2 or more commands.

    • A filter in a pipe is an output of one command which serves as input to the next.

    • EX ls -l | less 

    In this example, the output of the ls command is fed into less. By using this "| less" trick, you can make any command have scrolling output. I use this technique all   the time

    ";" is Chaining operator

    The semi-colon operator makes it possible to run, several commands in a single go and the execution of command occurs sequentially.

    [email protected]:/home/tecmint# apt-get update ; apt-get upgrade ; mkdir test






Upcoming Training