Quiz Entry - updated: 2026.06.20
What are practical examples of using pipes in Linux?
Chain small tools with | so each does one job — list-then-sort, read-then-filter, search-then-page.
The Unix philosophy is "small programs that do one thing well, connected by pipes." A few staples:
# Show last 2 lines of passwd file:
cat /etc/passwd | tail -n 2
labstudent:x:1004:1004::/home/labstudent:/bin/bash
labadmin:x:1005:1005::/home/labadmin:/bin/bash
# Sort files in reverse order:
ls | sort -r
Videos
Templates
Public
Pictures
Music
Downloads
Documents
Desktop
# Find files and page through results (including errors):
find / -name passwd 2>&1 | less
Note the first example uses cat file | tail, but tail -n 2 /etc/passwd would do the same without cat — piping cat into another tool is a common habit that's usually unnecessary ("useless use of cat"). The pipe shines when you genuinely need to combine tools, like ls | sort -r.
Tip: Add 2>&1 before the pipe (as in the find example) to push errors through it too — otherwise | less pages only stdout while errors scroll past on the screen.