Piping Commands Together: Essential Linux Data Processing
Learn how to use pipes in Bash to chain commands together. Master command chaining to filter, sort, and view command output efficiently in your terminal.

Previously in this course, we covered Standard Streams and Redirection: A Linux Guide for Developers, where you learned how to send command output into files. In this lesson, we add the power of pipes to our toolkit, allowing us to send the output of one command directly into the input of another, creating a seamless stream of data processing.
Understanding Pipes from First Principles
In Linux, a "pipe" (|) acts as a bridge. When you execute a command, it typically sends its output (Standard Output, or stdout) to your terminal screen. By placing a pipe between two commands, you redirect the stdout of the first command into the stdin (Standard Input) of the second command.
Think of it like a physical assembly line. A single command is a worker doing one task. A pipe allows you to pass the work-in-progress to the next station for further refinement. This is the foundation of command chaining, which allows you to build sophisticated data processing workflows without writing complex scripts.
Working Example: Chaining Commands
Let’s look at a practical scenario. You have a logs directory in your web server project (created in Project Kickoff: Provisioning Web Server Directories). Imagine that directory contains dozens of files, and you need to find a specific one or simply understand its size.
Instead of running ls -l and scrolling through hundreds of lines, we can pipe the output to less.
Bashls -l /var/log | less
How this works:
ls -l /var/loggenerates a long list of file details.- The
|operator catches that output before it hits your screen. lessreceives that data as its input and opens a scrollable, searchable buffer.
You can now use your arrow keys to navigate the list. When you are finished, press q to exit less and return to the prompt.
Combining Multiple Commands
You aren't limited to just two commands. You can chain as many as you need to reach your goal. For instance, if you want to count how many files exist in the /etc directory, you can chain ls and wc (word count):
Bashls /etc | wc -l
Here, ls lists the files, and wc -l counts the lines of the input it receives. This is the essence of effective data processing in the shell.
Hands-on Exercise
Let’s apply this to our ongoing project. Navigate to your project directory (referencing Mastering Absolute and Relative Paths in Linux if you need a refresher).
- List the files in your current working directory.
- Pipe that output to
grepto filter for a specific file name (e.g.,ls | grep "config"). - If you have many files, pipe the output to
lessto practice paging through the results.
Common Pitfalls
- Forgetting
stdincompatibility: Not all commands accept input from a pipe. For example,lsdoes not read from standard input. If you tryecho "file.txt" | ls, it will simply ignore the input and list the current directory anyway. Always check if a command is designed to process stream data. - Assuming order doesn't matter: The order of the chain is critical. You must place the command that produces the data first and the command that consumes/transforms it second.
- The "Permission Denied" Trap: If the first command fails (e.g., trying to
lsa directory you don't have access to), the error message is sent tostderr(Standard Error). Pipes only capturestdoutby default, so the error will still print to your screen, and the second command will receive nothing.
FAQ
Q: Is there a limit to how many commands I can pipe? A: Technically, you are limited only by system memory and the maximum command-line length of your shell, but for practical purposes, you can chain as many as you need to solve a problem.
Q: Why use less instead of just scrolling up in my terminal?
A: less is more memory-efficient for massive outputs and provides powerful search capabilities (press / while in less to search for text) that terminal scrollbars often lack.
Q: Can I save the result of a pipe to a file?
A: Yes! You can use the redirection operators you learned in our previous lesson at the very end of your pipe: ls -l | grep ".log" > log_list.txt.
Recap
Pipes are the "glue" of the Linux command line. By connecting the output of one process to the input of another, you can perform complex data filtering and inspection tasks in a single line. Mastering this allows you to manipulate logs, file lists, and system information with ease.
Up next: We will dive deeper into text filtering using the grep command to isolate the exact information you need from your data streams.
Work with me

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.

AI Automation & Agentic Workflow Development
Automate the repetitive work eating your time — content pipelines, data workflows, and agentic AI tasks that run themselves.

