• About
  • Privacy Policy
  • Contact us
  • Submit a story
Linux-News Linux news from the Blogosphere
  • Article
  • Howto
  • News
  • Opinion
  • Review
  • RSS Feed
  • Twitter
  • Facebook

Pipes in Unix Based Operating Systems

By
News
– December 21, 2011Posted in: Article, Howto, Submitted

Unix based operating systems like Linux offer a unique approach to join two discrete commands, and generate a new command using the concept of pipe(lines). For example, consider command1|command2. Here, whatever output is generated by the first command becomes the standard input for the second command. We can develop more and more complex Unix command sequences by joining many commands while maintaining input output relationships.

Another more Linux specific example would be ls -l|grep “^d”. This command displays details of only directories of the current working directory, i.e. the output of the ‘ls -l’ command becomes the input to the grep command, which displays only those lines that start with ‘d’ (they are nothing but the details of the files).

ls -l | grep “^d” | wc -l

This command displays number of directories in the given file.

grep “bash$” / etc / passwd | wc -l

This command displays number of users of the machine whose default shell is bash.

cut -t “: “-f 3 / etc / passwd | sort – n | tail – l

This command displays a number which is the largest used UID number in the system. Here, cut command first extracts UID’s of all the users in the system from the /etc / passwd file, and the same becomes input to sort; which sorts these numbers in numerical order and sends to tail command as input which in turn displays the largest number (last one).
tee command

The ‘tee’ command is used to save intermediate results in a piping sequence. It accepts a set of filenames as arguments and sends its standard input to all these files while giving the same as standard output. Thus, use of this in piping sequence will not break up the pipe.

For example, if you want to save the details of the directories of the current working directory while knowing their using the above piping sequence we can use tee as follows. Here, the file xyz will have the details of the directories stored.

ls -l | grep “^d” |tee xyz | wc -l

The following piping sequence writes the number of directories into the file pqr while displaying the name on the screen.

ls -l | grep “^d” | tee xyz | wc -l |tee pqr

cmp command

The cmp utility compares two files of any type and writes the results to the standard output. By default, cmp is silent if the files are the same. If they differ, the byte and line number at which the first difference occurred is reported.

Bytes and lines are numbered beginning with one.

For example, cmp file1 file2
comm command

comm is a command used to compare two sorted files line by line.

Compare sorted files LEFT_FILE and RIGHT_FILE line by line.

-1 suppresses lines that are unique to the left file.

-2 suppress files that are unique to the right file.

-3 suppress lines that appear in both the left file and the right file. For example, comm p1 p2.

A pipe thus helps connect a set of processes, so that the output of one becomes the input of another. It lets a user browse through a large amount of data in a convenient manner.

Linux2Aix is an upbeat Linux blog containing all the latest and the newest Linus news and how-to’s for both amateur and professional Linux lovers

Article Source: http://EzineArticles.com/?expert=Erick_M_Aqqa

Article Source: http://EzineArticles.com/6511631
Tags: command sequences, command2, default shell, filenames, grep command, input output, linux, operating systems, pipe lines, piping, Unix, unix command

About News

1 Comment

  1. Someone
    Posted December 22, 2011 at 11:45 AM

    This article has almost no information about pipes and how they work.
    Instead it is a random collection of standard *nix commands with very minimal explanation of their purpose or usage. It seems almost a coincidence that it includes pipes at all.

Leave a Reply Cancel reply

Your email address will not be published.

  • Suggested Sites
    http://linuxaria.com everything about Linux http://linuxaria.com everything about Linux
  • Curated topic
  • Recent Posts
    • Free Printable Coloring Pages in PDF Format: Color Your World
    • How to Create a PDF from an Image: The Ultimate Guide
    • How to Master PDF Manipulation in Python: A Comprehensive Guide
    • How to Utilize the Noodles & Company Menu PDF for a Delightful Dining Experience
    • How to Delete Pages in PDF: The Ultimate Guide
    • How to Find the Perfect Map of the US in PDF Format
    • CFA Level 2 Summary Notes PDF: Master the Material, Conquer the Exam
    • Download Your Comprehensive 504 Accommodations List PDF Guide
    • Unlock Your Career Journey: The Ultimate Guide – MIT Career Handbook PDF
    • Unlock Peak Fitness with Our Comprehensive Bodyweight Workout Plan PDF
  • Ranking

About Arras WordPress Theme

All site content, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.