Everyday Guidebooks
Cover of Linux for Beginners

Cybersecurity & IT

Linux for Beginners: Processes Across the Pipe

A Practical Guide to Command Input, Output, Redirection, and Error Handling

by Todd Michael

Available now

What actually happens when you join Linux commands with a pipe? If you are looking for a linux for beginners book that explains more than a list of commands, this guide follows the data step by step.

Learn how a command reads input, where its output goes, and why error messages sometimes appear where you do not expect them. Practice redirecting streams, building pipelines, checking exit status, and finding the stage that caused a problem. Short exercises use small, readable examples so you can experiment without needing a complex setup.

Along the way, you will trace standard input, standard output, and standard error; compare files and pipes; and learn how quoting and redirection order affect results. Review questions and guided solutions help reinforce the concepts for everyday terminal work and entry-level IT certification study.

Start with one command. Finish with a clearer picture of how commands work together.

Contents
  1. 1. Meet the Shell and the Command
  2. 2. A Process with Three Streams
  3. From Command to Process
  4. The Three Standard Streams
  5. File Descriptors: The Numbers Behind the Names
  6. Follow a Simple Output
  7. Arguments Are Not Standard Input
  8. A Command That Reads Standard Input
  9. Normal Output and Diagnostics
  10. Seeing the Separation
  11. A Stream Is Not Necessarily a Screenful
  12. Practice: Trace Before You Run
  13. Practice Review
  14. 3. Reading from Standard Input
  15. 4. Sending Output to Files
  16. 5. Separating Results from Errors
  17. 6. Your First Pipe
  18. 7. Filters That Transform Text
  19. 8. Building Longer Pipelines
  20. 9. Arguments, Expansion, and Quoting
  21. 10. Exit Status and Success
  22. 11. Failures Inside a Pipeline
  23. 12. Handling Errors Deliberately
  24. 13. Tracing and Repairing Broken Pipelines
  25. 14. Putting the Streams Together
  26. The Assignment
  27. Build the Pipeline One Stage at a Time
  28. Write the Report and Capture Diagnostics
  29. Check the Pipeline, Not Just the Report
  30. Exercise: Investigate a Missing Input File
  31. Inspect Individual Stage Statuses
  32. A Safer Report Update
  33. Cumulative Review
  34. One Last Independent Test
  35. Other Books by Todd Michael

Read a sample: 1. Meet the Shell and the Command

A Linux command line can look deceptively simple: a prompt, a few words, and perhaps a result. Behind that small exchange are several distinct jobs. A shell reads what you type, interprets it, and carries out the requested action. Sometimes it handles the action itself; sometimes it starts another program. The program may receive information, produce a result, or report a problem.

Understanding those jobs makes commands easier to combine and troubleshoot. Before connecting commands with pipes, you need a comfortable place to practice and a clear picture of what happens when you press Enter.

In this chapter, you will create a practice directory, recognize the shell prompt, and run commands with arguments. You will also compare a shell built-in with an external program—a distinction that will help explain where commands come from and why they behave differently.

On a Linux desktop, open an application named Terminal, Console, or something similar. If you are using a remote Linux system, connect using the method provided for that system. Either way, you are looking for a text interface in which you can enter commands.

The terminal and the shell are related but different:

- The terminal provides the interface where you type and see text. - The shell reads your command lines and interprets them. - A program performs a task when the shell starts it.

A terminal is like a workspace window; the shell is the command interpreter working inside it. The shell can run many programs during a single session.

Examples in this book use Bash, a common Linux shell. If you are unsure which shell is running, enter:

bash bash

This starts a Bash shell inside your current shell, assuming Bash is installed. You can continue the exercises there. When you eventually type exit, you return to the shell that started it.

When the shell is ready to read a command, it normally displays a prompt. It might look something like this:

text alex@workstation:~$

Your prompt will probably look different. It may show a username, a machine name, a directory, or other information. The ending character is often $ for a regular user. A prompt ending in # commonly indicates an administrative shell; use a regular user account for these exercises when possible.

The prompt is not part of the command. In this book, command examples appear without it:

bash pwd

Type pwd and press Enter. Do not type a dollar sign merely because you see one in a prompt elsewhere.

The command prints the path of your current working directory: the location the shell uses as its starting point for many file operations. Your result might be:

text /home/alex

Your username and path may differ. Linux paths are case-sensitive, so Practice and practice refer to different names.

After the output, the shell displays another prompt. That new prompt means the shell is ready for another command. It does not necessarily mean that the previous command succeeded; later in the book, you will learn a more reliable way to check.

A dedicated directory keeps the files you create in this book together. The following command takes you to your home directory:

bash cd

Now check your location:

bash pwd

Create a directory for the exercises:

bash mkdir linux-pipes-practice

The command name is mkdir, short for “make directory.” The word after it is the name of the directory to create. If the command succeeds, it will usually produce no visible output. That silence is normal.

If you receive a message saying the directory already exists, choose a different name, such as linux-pipes-practice-new, and use that name in the next command. If you receive a permissions error, check that you are in a location where your account can create files.

Move into the new directory:

bash cd linux-pipes-practice

Then confirm where you are:

bash pwd

The displayed path should end in linux-pipes-practice, unless you chose another name. For example:

text /home/alex/linux-pipes-practice

You can inspect the directory with:

bash ls

A newly created directory will normally have no visible entries, so ls may print nothing before the next prompt. This does not mean the terminal is broken. It means the command has no names to display.

For the exercises ahead, check your location with pwd whenever you are uncertain. A practice directory is helpful because relative filenames refer to the current working directory. It does not prevent a command from reaching other locations, so read commands before running them, especially when they change or remove files.

A simple command line often contains a command name followed by one or more arguments. Arguments provide information that the command uses: a directory name, text to print, or an option that changes its behavior.

Consider:

bash mkdir notes

Here, mkdir is the command name, and notes is an argument. The argument tells mkdir which directory to create. Run the command inside your practice directory, then list the contents:

bash ls

You should see:

text notes

The shell separates the command name and arguments as it interprets the line. For these simple examples, spaces mark the boundaries between words. In Chapter 9, you will see how quoting lets a single argument contain spaces and how the shell can transform parts of a command line before a program starts.

You can give some commands more than one argument:

bash mkdir drafts reports

This asks mkdir to create two directories, drafts and reports. Check the result:

bash ls

More Cybersecurity & IT

Cover of The White Hat Bible, Volume 1The White Hat Bible, Volume 1Available nowCover of The White Hat Bible, Volume 2The White Hat Bible, Volume 2Available nowCover of The White Hat Bible, Volume 3The White Hat Bible, Volume 3Available nowCover of The White Hat Bible, Volume 4The White Hat Bible, Volume 4Available nowThe White Hat Bible, Volume 5Available nowCover of The White Hat Pocket GuideThe White Hat Pocket GuideAvailable now

About Todd Michael

Todd Michael is an American author and the founder of ToddMichael.tv. He writes practical, plain-English books on money, health, preparedness, technology, games, humor and more.

About the author Todd Michael · Todd Michael’s author site

Part of the ToddMichael.tv network.