Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How do I pipe the output of one command to another in unix? For example, If I want to pipe the output of sort to tail, how would I do that?

Thanks in advance.

share|improve this question

migrated from serverfault.com Feb 13 at 2:05

2 Answers

The | character is used to pipe the stdout of one program to the stdin of another.

sort file.txt | tail

This will work in any POSIX compliant shell.

share|improve this answer

Try doing this :

sort file.txt | tail

See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html and search 2.9.2 Pipelines paragraph

share|improve this answer
Just that in this case sort has to finish doing its job before tail starts its. The idea is that the second in line gets to start working as soon as the first one gives it something to ork on. – vonbrand Feb 13 at 3:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.