This Season
 

Pipe Unix Tutorial

The UNIX command pipe works like a physical pipe. It connects two UNIX commands and thus facilitates a one-way flow of data. Like a physical pipe, which controls the flow of fluid, the pipe command gives users control of the output of the commands being executed.

Related Searches:
    1. Basics

      • Similarities between a physical pipe joint and UNIX Pipe command

        Just like a physical joint of two pipelines that gives the illusion of one continuous pipe, the pipe command (|) lets two UNIX commands work together. For example:

        $ cat abc.txt | wc --l
        23

        The UNIX command "cat" is used to retrieve the contents of a file, while the "wc -l" command does a word count of the input stream of words. The pipe command "|" in this example passes the output of the "cat" of file abc.txt (which lists down the contents of the file abc.txt) to "wc -- l," which performs a word count on the contents. In the example, the result is 23, which means the file abc.txt contains 23 words. If these commands were executed separately, it would be difficult to count the number of words in the file abc.txt. Pipe lets the user achieve this by combining the two commands.

        In a physical pipeline joint, the output of one pipe may not be the same as the input for the other pipe, as illustrated in the diagram. Similarly in UNIX, it is possible that the output quantity of one command may not match the input quantity of the other. The pipe command gives you the ability to control the flow. If one command acts faster than the other, it readjusts the flow. For example:

        $ ls | more

        The "ls" command lists the contents of a directory. However, this may result in excess output on the terminal if the directory consists of lots of files. Therefore, in order to control the output and make more sense of it, the pipe command (|) is used to pass this output to another command, "more" (which limits the output to a page). This results in the output being shown in one page. Only when the user presses "Enter" is the next page of output shown.

      Flexibility

      • The pipe command has the ability to join more than two UNIX commands, providing more flexibility to the user. However, to use this, users should know what they want overall and what individual commands do. For example:

        $ls | grep ^d | grep notes | wc --l

        The command above intends to find all sub-directories inside a directory that contain the word "notes" in them and then does a word count. This is done by the combination of the four commands shown above. The first command, "ls," lists the content of the current directory. The second command, "grep ^d," finds the sub-directories from that list. The third command, "grep notes," finds the sub-directories that contain the word "notes." The fourth command, "wc --l," does a word count from the output.

        The main point to remember while using the pipe command is that the output from the command on the left is to the standard output and the input to the command to the right is from the standard input. So if there are UNIX commands that send outputs not to standard outputs (terminals, for example) in which the command is run, the pipe command should not be used.

      Programming

      • Pipelines can be created in C/C++ programs, too, using the pipe () method. This call creates a pipe object, which creates two new file descriptors, fd1 and fd2. A read from fd1 accesses the data written to fd2 on a FIFO (First In First Out) basis, and a read from fd2 accesses the data written to fd2 on a FIFO basis.

    Related Searches

    References

    Resources

    Read Next:

    Comments

    You May Also Like

    • UNIX C Tutorial

      The Unix Operating System was created using the C programming language. Therefore, there is support for C programming in every Unix and...

    • GREP Tutorial for Unix

      Searching for an occurrence of a specified pattern of characters within a file or standard input is a common task for Unix...

    • A Pipe Bending Tutorial

      When you're involved in a plumbing, heating, ventilation, air-conditioning or other project, you may find it necessary to bend piping to get...

    • Unix Screen Command Tutorial

      The Unix command line provides access an extensive list of software tools designed to maximize command line efficiency. The Screen command features...

    • Tutorial for a Unix Join

      The Unix join command takes two text files as input and joins lines that start with a common text field together, dropping...

    • Tutorial for Unix LS

      UNIX is an operating system originally developed in 1969, but it later split into a number of branches, derivatives and new systems,...

    • Memory Logging Tools

      Memory Logging Tools. Memory logging is in the field of ground drilling. In memory logging, logging tools are inserted into the ground...

    • A Tutorial for AIX on Unix

      AIX is IBM's flavor of the Unix Operating System. It runs on IBM's RISC processors and integrates AT&T's System V UNIX with...

    • About Unix

      UNIX is one of many operating systems available for use on personal computers, servers and networks. Some deem it to be more...

    • How to Learn UNIX at Home

      The Unix platform was invented in the 1960s and it is an operating system that operates on a command-based interface. Unix is...

    • Unix Mail Tutorial

      The UNIX system is a large part of everyday life. As the Open Group website points out, life as we know it...

    • How to Create a Named Pipe

      A powerful feature of Linux, along with other varieties of Unix, is the ability for one command to provide the input to...

    • PVC Plumbing Tutorial

      Polyvinyl chloride (PVC) plumbing is becoming an increasingly popular material in both residential and commercial construction due to its many benefits and...

    • Unix Cut Command Tutorial

      The Unix "cut" command is used to locate and cut characters or fields from an input file. Unlike the "cut" command in...

    • How to Check on Running Jobs in the Background in Unix

      If you are working on a Unix platform and run multiple processes at one time, it can be useful to check on...

    • Unix Command Tutorial

      Although there are graphical user interfaces available for Unix systems, it is still common to type commands at the terminal window. If...

    • How to Add a Prefix to a Line in UNIX

      Use the following command to go through every line of a text file and add a prefix: cat textfilename | awk '{print...

    • Tutorial for Unix

      UNIX is a powerful operating system that puts a great deal of responsibility in the hands of the Unix Administrator. UNIX gives...

    Follow eHow

    Related Ads