---
title: "Unleashing the Power of the Pipe Command in Linux"
description: "Unlock the prowess of the pipe command in Linux to streamline tasks, boost productivity, and simplify complex operations effortlessly!"
canonical: "https://adamtheautomator.com/pipe-command-in-linux/"
---

# Unleashing the Power of the Pipe Command in Linux

> Unlock the prowess of the pipe command in Linux to streamline tasks, boost productivity, and simplify complex operations effortlessly!

Source: https://adamtheautomator.com/pipe-command-in-linux/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Unleashing the Power of the Pipe Command in Linux](https://adamtheautomator.com/wp-content/uploads/2024/03/pipe-command-in-linux-1.jpg)

# Unleashing the Power of the Pipe Command in Linux

[![](https://secure.gravatar.com/avatar/b1faae2f957a0d43de36dfd25e8c08537718fb87c49cfd0a15b0e860a7f7b9a0?s=192&d=mm&r=g)Mercy Bassey](https://adamtheautomator.com/author/mercy-bassey/)22 March 20247 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Linux](/tag/linux/)[Linux Shell Scripting](/tag/linux-shell-scripting/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Mastering grep Integration with the Pipe Command in Linux](#mastering-grep-integration-with-the-pipe-command-in-linux)
*   [Manipulating Data with the Pipe and awk Commands](#manipulating-data-with-the-pipe-and-awk-commands)
*   [Harnessing sed for Streamlined Text Editing](#harnessing-sed-for-streamlined-text-editing)
*   [Monitoring the System Memory and CPU Performances](#monitoring-the-system-memory-and-cpu-performances)
*   [Streamlining File System Management](#streamlining-file-system-management)
*   [Enhancing System Insights Through Log File Analysis](#enhancing-system-insights-through-log-file-analysis)
*   [Conclusion](#conclusion)

Does dealing with complex tasks in the Linux command line make you long for a quicker solution? Picture this: effortlessly passing the output of one command to another like magic! The pipe command in Linux is your ticket to crafting a seamless chain of operations that gets the job done efficiently.

In this tutorial, you will uncover the power of the pipe command to revolutionize your workflow in Linux. Seamlessly feed the output of one command as input to another, saving precious time and effort along the way.

Sounds good? Dive right in and supercharge your productivity!

## Prerequisites

Before harnessing the pipe command in Linux, ensure you have a Linux machine. This tutorial uses an Ubuntu 22.04 LTS.

Related:[Install Ubuntu Server 20.04: A Step-by-Step Walkthrough](https://adamtheautomator.com/install-ubuntu/)

## Mastering `grep` Integration with the Pipe Command in Linux

As you start getting to know the pipe command, one of the tools you will quickly become acquainted with is the [`grep`](https://www.geeksforgeeks.org/grep-command-in-unixlinux/) command.

You know those moments when you are stuck in log file hell, spotting errors or navigating through directories? Cue the pipe (`|`) and `grep` commands! Together, they make tasks quicker and more precise.

Related:[Grep with Regex: Your Guide to Efficient System Troubleshooting](https://adamtheautomator.com/grep-with-regex/)

To see how the pipe (`|`) command works with `grep`, follow these steps:

1\. Open a terminal and execute the following commands to perform the following:

*   Create three files (`touch`) (i.e., _`/report.txt`_, _`/summary.txt`_, and `/notes.pdf`) in the `~/Documents` directory.
*   Change the working directory (`cd`) to the `~/Documents` directory.

These commands do not provide any output, but the files will be created, which you will verify in step two.

```bash
touch ~/Documents/report.txt ~/Documents/summary.txt ~/Documents/notes.pdf
cd ~/Documents
```

2\. Next, run the command below, chaining `ls` with the `grep` command to display files that end with `.txt` only.

This command works as follows:

*   `ls` – Lists all files in the directory.
*   `|` – Passes the output of `ls` to `grep.`
*   `grep '.txt$'` – Filters and displays only those filenames ending with `.txt`.

```bash
ls | grep '.txt$'
```

If successful, the command returns the files _**report.txt**_ and _**summary.txt**_, where the search term _**.txt**_ colored in red, as shown below.

The pipe (`|`) command is not a standalone command that can be used independently but lets you chain commands. This functionality allows you to direct one command’s output into another’s input, performing complex tasks with minimal effort.

![pipe command in linux - Enhancing file searches with the pipe (|) and grep commands](https://adamtheautomator.com/wp-content/uploads/2024/03/image-149.png)

Enhancing file searches with the pipe (`|`) and `grep` commands

3\. Now, repeat the same command in step two, but this time, change the search term to `report` regardless of its file extension.

```bash
ls | grep 'report'
```

Notice the command returned the _**report.txt**_ file with the filename in red.

![Filtering the search term](https://adamtheautomator.com/wp-content/uploads/2024/03/image-148.png)

Filtering the search term

## Manipulating Data with the Pipe and `awk` Commands

While `grep` is an excellent choice for searching and filtering text based on patterns, [Awk](http://awk.freeshell.org/) shines in more complex data manipulation through simple and chained commands.

Awk’s prowess is particularly notable when combined with the pipe (`|`) command for enhanced functionality and streamlined data processing.

To manipulate data with combined pipe (`|`) and `awk` commands, proceed with the following:

1\. Execute the following command to generate a simple [CSV file](https://adamtheautomator.com/csv-file/) named _`data.csv`_ (arbitrary) `~/Documents` directory.

This command provides no output to the terminal but inputs the specified content in the CSV file.

```bash
echo -e "name,age,role\nAlice,30,Developer\nBob,35,Manager\nCharlie,25,Designer" > data.csv
```

Related:[Echo Command in Bash Shell : Discover the Many Uses](https://adamtheautomator.com/echo-command-in-bash/)

2\. Once generated, run the command below to list only the names and roles from the CSV, excluding the age column.

This command achieves the following:

*   Output the content of the file using (`cat data.csv`).
*   Direct the output to `awk` with the pipe (`|`) command.
*   Specify that commas (`,`) separate fields (`-F`).
*   Display the first and third fields (`{print $1, $3}`) (name and role) from each line.

```bash
cat data.csv | awk -F, '{print $1, $3}'
```

The output below shows a list of data from only tic fie: **name** and **role**.

![Displaying targeted data with the pipe (|) and awk commands](https://adamtheautomator.com/wp-content/uploads/2024/03/image-151.png)

Displaying targeted data with the pipe (`|`) and `awk` commands

3\. Lastly, pipe (`|`) the `data.csv` file’s content to `awk` to calculate the average age of the individuals.

Apart from data manipulation, Awk also supports basic mathematical operations, making it a versatile tool for various tasks.

```
cat /data.csv | awk -F, 'NR>1 {sum += $2; count++} END {print "Average Age:", sum / count}'
```

If successful, you will see an **Average Age** of **30** in the output.

![Performing basic mathematical operations alongside data manipulation](https://adamtheautomator.com/wp-content/uploads/2024/03/image-150.png)

Performing basic mathematical operations alongside data manipulation

## Harnessing `sed` for Streamlined Text Editing

Awk makes complex data manipulation and analysis look easy. But for in-line text transformations and pattern-based editing, talk [`sed`](https://www.gnu.org/software/sed/manual/sed.html). When combined with the pipe (`|`) command, `sed` can apply text modifications directly to the streamed output of other commands.

For instance, when processing log files, you can extract specific information or change certain patterns.

To harness `sed` for streamlined text editing, carry out the following:

1\. In the _~/Documents_ directory, open the _greetings.txt_ file in your preferred code editor (i.e., `nano` or [`vim`](https://adamtheautomator.com/vim-for-linux/)).

2\. Next, add the following lines to the file as the contents you will manipulate in the subsequent step.

Related:[How to Get Started With Gedit Linux](https://adamtheautomator.com/gedit-linux/)

```
Hello, world!
Welcome to the world of Linux.
Goodbye, world!
```

3\. Now, run the `cat` command below to execute the following actions:

*   View (`cat`) the content of the `greetings.txt` file.
*   Pipe (`|`) the resulting output to `sed`.
*   Change every occurrence of the word `world` to `universe` like so.

```bash
cat greetings.txt | sed 's/world/universe/g'
```

Assuming all goes well, you will see an output similar to the one below, where all **worlds** are changed into **universe**.

![Replacing data via sed and pipe (|) commands](https://adamtheautomator.com/wp-content/uploads/2024/03/image-152.png)

Replacing data via `sed` and pipe (`|`) commands

## Monitoring the System Memory and CPU Performances

Beyond just handling text and data, the pipe (`|`) command shines in system administration tasks. You know, like keeping tabs on how your system’s doing.

This capability turbocharges basic commands, letting you process and analyze data on the fly—a big deal in keeping your system in tip-top shape.

To monitor system memory and CPU performances, proceed with these steps:

Execute the following commands to run `top` in batch mode (`-b`) to allow piping.

This command executes once (`-n 1`) and then filters the output for `chrome`.

```bash
# Move away from the ~/Documents directory 
cd .. 
# Displaying the top processes and filtering for those related to "chrome."
top -b -n 1 | grep chrome
```

The following result is a snapshot of current CPU usage for Chrome processes.

![Viewing chrome processes with the top and pipe (|) commands](https://adamtheautomator.com/wp-content/uploads/2024/03/image-154.png)

Viewing chrome processes with the `top` and pipe (`|`) commands

> 💡 _The `top` command provides a dynamic, real-time view of a running system. You can also pipe its output to `grep` to filter for specific processes or keywords._

Now, run the command below to combine `awk` and `free` to display the total and available memory (`/^Mem:/`) on your machine in an easy-to-read format (`-h`).

```bash
free -h | awk '/^Mem:/ {print "Total Memory: " $2 "\nAvailable Memory: " $7}'
```

![Extracting the system’s total and available memory](https://adamtheautomator.com/wp-content/uploads/2024/03/image-153.png)

Extracting the system’s total and available memory

## **Streamlining File System Management**

Navigating through directories, organizing files, and ensuring data integrity are only a few challenges system administrators and users face. How do you overcome this challenge? Streamlining file system management is just one of the solutions the pipe (`|`) command offers to enhance productivity and simplify complex file operations.

Combining utilities like `du` (disk usage) and `sort` to identify large files or directories helps in effective disk space management.

To streamline file system management, proceed as follows:

Execute the following command to identify the `10` (arbitrary) largest directories within the working directory (in this case, the _home_ directory).

This command performs the following:

*   `du -sh *` – Compute each item’s size in the current directory.
*   `sort -rh` – Sort items in reverse order of size.
*   `head -n 10` – Display the top ten largest items.

```bash
du -sh * | sort -rh | head -n 10
```

As shown below, the list displays the top 10 largest directories within the working directory.

![Viewing the largest ten directories](https://adamtheautomator.com/wp-content/uploads/2024/03/image-156.png)

Viewing the largest ten directories

Identify files larger than a certain size (e.g., 100MB) within the _~/Music_ directory using the following command:

Now, run the command below to complete these tasks:

*   `find . -size +50M` – Find files larger than 50 MB within a specific directory (i.e., _~/Music_).

Related:[The Many Ways On Ubuntu to Find Files](https://adamtheautomator.com/ubuntu-to-find-files/)

*   `xargs du -h` – Calculate the disk usage of each file and display the sizes in a human-readable format.
*   `sort -rh` – Sort items in reverse order by size (larger than 50 MB), displaying the largest files at the top.

```bash
find . -size +50M | xargs du -h | sort -rh
```

![Finding files and directories larger than 50 MB](https://adamtheautomator.com/wp-content/uploads/2024/03/image-155.png)

Finding files and directories larger than 50 MB

> 💡 _Tip: You can explicitly target files only (`-f`) with the following command instead:_  
> _`find . -type f -size +50M | xargs du -h | sort -rh`_

## Enhancing System Insights Through Log File Analysis

Amidst the complexities of managing diverse systems, uncovering the root cause of issues can often feel like finding a needle in a haystack. Fortunately, log file analysis, the beacon of light in the sea of system data, is within reach.

Piping, especially when combined with commands like `grep`, `awk`, `sort`, and `uniq`, turns log file analysis from a daunting task into a manageable one.

To unlock invaluable insight through log file analysis, proceed with the following:

Execute the following commands to find entries tagged with `error` from the system logs (`syslog`).

System logs in Linux are often stored in `/var/log` and are often logged with tags like error, fail, or critical.

```bash
cd /var/log
grep -i error syslog
```

The `-i` option makes the search case-insensitive, ensuring you catch Error, ERROR, and any other case variations (in red).

![Finding error logs](https://adamtheautomator.com/wp-content/uploads/2024/03/image-157.png)

Finding error logs

Lastly, run the following command to see how frequently errors occur, and pipe the output to `wc -l` to count the number of lines.

```bash
grep -i error syslog | wc -l
```

The output below says the total number of error messages in the `syslog` is **146**.

![Viewing the number of lines of error messages](https://adamtheautomator.com/wp-content/uploads/2024/03/image-158.png)

Viewing the number of lines of error messages

## Conclusion

Throughout this tutorial, you have delved into the powerful world of the pipe command in Linux. You have mastered transforming complex Linux tasks into streamlined operations effortlessly. You have unlocked a whole new level of efficiency and productivity in your Linux adventures.

How else would you like to experiment further with the pipe command? Why not consider diving into [real-time monitoring](https://askubuntu.com/questions/562222/piping-in-real-time) [with piping](https://askubuntu.com/questions/562222/piping-in-real-time)? Or perhaps explore its [integration into scripting for automation](https://bash.cyberciti.biz/guide/Pipes)?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpipe-command-in-linux%2F&text=Unleashing%20the%20Power%20of%20the%20Pipe%20Command%20in%20Linux)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpipe-command-in-linux%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpipe-command-in-linux%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/07/How-to-Update-Ubuntu-IP-and-Hostname-via-Bash.jpg)

### [How to Update Ubuntu IP and Hostname via Bash](/change-linux-ip-hostname-bash-script/)

Discover and learn how to change a Linux IP and Hostname via a Bash script in this new tutorial by ATA Learning!

![](https://adamtheautomator.com/wp-content/uploads/2022/06/Behind-the-Scenes-of-Linux-Timezones-Dates-and-Time.jpg)

### [Effective Management Linux Timezones (Step by Step Tutorial)](/linux-timezones/)

Best practices for managing Linux timezones, dates, and time with practical examples for the IT administrator!

![](https://adamtheautomator.com/wp-content/uploads/2021/12/Manage-Directory-and-File-Permissions-with-chmod-Recursive.jpg)

### [Manage Directory and File Permissions with chmod Recursive](/chmod-recursive/)

Learn how to leverage the powerful chmod recursive command to ensure correct permissions across all of your files and folders!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
