What Is A Pipe
Part of the Fundamentals section of Coddy's Terminal journey — lesson 43 of 82.
Redirection lets you send output to files, but what if you want to send the output of one command directly into another command? That's where pipes come in.
A pipe connects the standard output of one command to the standard input of another using the | symbol. Instead of saving intermediate results to a file, data flows directly between commands.
cat names.txt | sortThis takes the output of cat names.txt and feeds it directly into sort. The sorted result appears on your screen without creating any temporary files.
Without pipes, you would need multiple steps:
cat names.txt > temp.txt
sort < temp.txt
rm temp.txtThe pipe accomplishes the same thing in a single, elegant command. Think of it as connecting commands like sections of a pipeline — data enters one end and flows through each command in sequence until it reaches the final output.
Challenge
EasyUse a pipe to read the contents of fruits.txt and sort them alphabetically in a single command.
Run a command that:
- Uses
catto readfruits.txt - Pipes the output to
sortusing the|symbol
Hint: The format is
cat filename | sort. The output ofcatflows directly intosortwithout needing any intermediate files.
Cheat sheet
A pipe connects the standard output of one command to the standard input of another using the | symbol:
cat names.txt | sortThis takes the output of cat names.txt and feeds it directly into sort, eliminating the need for temporary files.
Without pipes, you would need multiple steps:
cat names.txt > temp.txt
sort < temp.txt
rm temp.txtData flows through each command in sequence like sections of a pipeline.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline