Study guide
3.2a Pipes, Redirection, and Basic Regular Expressions
LPI Linux Essentials Certificate 010-160
Track your progress as you read
Finished sections get a check mark.
1 Introduction & Exam Overview
1.1 Current Exam Facts 1.2 Study Strategy & Blueprint Weights
2 Topic 1: The Linux Community and a Career in Open Source
1.1 Linux Evolution and Popular Operating Systems 1.2 Major Open Source Applications 1.3 Open Source Software and Licensing 1.4 ICT Skills and Working in Linux
3 Topic 2 Part A: Command Line Basics & Getting Help
2.1a Bash Shell, Command Syntax & Variables 2.1b Quoting, History & Safe Command Syntax 2.2 Using the Command Line to Get Help
4 Topic 2 Part B: Directories, Listing & File Operations
2.3 Using Directories and Listing Files 2.4 Creating, Moving and Deleting Files
5 Topic 3 Part A: Archiving & Searching Data
3.1 Archiving and Compression on the Command Line 3.2a Pipes, Redirection, and Basic Regular Expressions 3.2b grep and Text Extraction Tools
6 Topic 3 Part B: Turning Commands into Scripts
3.3a Script Basics: Shebang, Variables, and Arguments 3.3b Loops, Exit Status, and Simple Conditionals 3.3c Editors, chmod +x, and Running Scripts
7 Topic 4 Part A: Choosing an OS, Hardware & FHS Basics
4.1 Choosing an Operating System 4.2 Understanding Computer Hardware 4.3a Where Programs and Configuration Live (FHS Basics)
8 Topic 4 Part B: Processes, Logs & Networking
4.3b Processes, Memory & Logs 4.4 Your Computer on the Network
9 Topic 5: Security and File Permissions
5.1 Basic Security and Identifying User Types 5.2 Creating Users and Groups 5.3 Managing File Permissions and Ownership 5.4 Special Directories and Files
3.2a Pipes, Redirection, and Basic Regular Expressions
Key Takeaways Explain This Topic AI
A pipe (|) sends stdout of the left command into stdin of the right command
overwrites (or creates) a file with stdout; >> appends stdout to a file
< feeds a file into a command as stdin; 2> redirects stderr; 2>&1 merges stderr into stdout
Basic regex atoms on Essentials: . any one character, [ ] character class, * zero-or-more of the previous atom, ? optional (ERE) / shell glob awareness
Quote patterns with spaces or metacharacters so the shell does not expand them before grep or similar tools see them
Last updated: July 2026
Connecting commands and shaping I/O (objective 3.2)
Objective 3.2 is about searching and extracting data . Before the individual tools ( grep , sort , cut , and friends), you need the plumbing : pipes, redirection, and a little regular expression vocabulary so patterns mean what you intend.
Pipes: |
A pipe connects two programs. The standard output (stdout) of the left command becomes the standard input (stdin) of the right command — no temporary file required. ps aux | grep nginx
- dmesg | grep -i usb
- cat access.log | grep " 404 "
Read pipelines left to right: “generate text, then filter or transform it.” You can chain several stages: grep "ERROR" app.log | sort | uniq -c
That pattern — produce → filter → refine — is the heart of day-to-day Linux text work and a frequent exam theme.
Pipes carry stdout , not stderr, unless you merge streams first (see 2>&1 below).
Pipe versus redirect: grep error app.log | wc -l counts on the fly; grep error app.log > hits.txt saves matches to a file. Pick | for another command, > / >> for a file.
Redirection operators
Every process has three standard streams:
- Stream Number Typical use
- stdin 0 Input (keyboard or a file/ | )
- stdout 1 Normal output
- stderr 2 Error messages
- Writing and appending: > and >>
- Operator Effect
- > Redirect stdout to a file — overwrite (create if missing)
- >> Redirect stdout — append to the file echo "first" > notes.txt # creates or truncates notes.txt
- echo "second" >> notes.txt # adds a second line
- ls /etc > listing.txt # save directory listing
Danger: > truncates immediately. command > important.txt with a typo can wipe important.txt before you notice. Prefer >> when you mean “add to the log.”
- Reading input: < sort < names.txt
- wc -l < app.log
< feeds a file into stdin. Many commands also accept filenames as arguments ( sort names.txt ).
Errors: 2> and merging with 2>&1
- Operator Effect
- 2> Redirect stderr to a file (overwrite that error file)
- 2>> Append stderr to a file
- 2>&1 Send stderr to the same place as stdout ls /exists /missing > out.txt 2> err.txt
- # out.txt gets the successful listing; err.txt gets the error for /missing
- ls /missing > all.txt 2>&1
- # both stdout and stderr land in all.txt
Order tip: write > file 2>&1 (redirect stdout to file , then point stderr at wherever stdout now goes). The reverse order 2>&1 > file first merges stderr to the terminal’s stdout, then only redirects stdout — a classic fill-in trap.
Worked silence-and-pipe: find /var/log -name "*.log" 2>/dev/null | head discards permission errors on stderr so only successful path names flow into head . /dev/null is the “bit bucket.”
Basic regular expressions
Linux Essentials expects awareness of basic regex atoms used with tools like grep . A regular expression is a pattern , not always a literal string.
- Atom Meaning Example idea
- . Any one character err.r matches error , errar
- [ ] Character class — one char from the set [Ee]rror matches Error or error
- * Zero or more of the previous atom fail* → fai plus zero or more l
? In extended regex ( grep -E ), previous atom optional; also a shell glob for “one char” — know the context grep "err.r" app.log
grep "[0-9][0-9][0-9]" codes.txt # three digits in a row (BRE style)
grep -E "colou?r" words.txt # color or colour with ERE ?
Shell globs vs regex: In the shell, * means “any string” in filenames ( ls *.log ). Inside grep ’s default basic regular expressions , * repeats the previous piece. Quoting protects your intent: grep "file.txt" notes # . means any character — matches fileXtxt too
grep "file\.txt" notes # escaped dot = literal period
When a pattern has spaces or shell-special characters, quote it so the shell does not expand globs or split words before grep runs: grep "connection refused" /var/log/syslog
Tiny practice patterns
- Goal Pattern sketch
- Lines with Error or error [Ee]rror or use grep -i error
- Any character between a and c a.c
- Digit [0-9]
- Literal dot in v1.2 v1\.2
You do not need advanced Perl-style regex for 010-160. Own . , [ ] , * , and when ? is optional-atom (ERE) versus a shell wildcard.
Fill-in traps: wrong merge order ( 2>&1 > file vs > file 2>&1 ); using > when the story says append; unquoted * so the shell expands names before grep .
- Putting it together cut -d: -f1 /etc/passwd | sort | uniq > users.txt
- cmd_that_warns 2>&1 | grep -i warn
- Exam mindset
| connects stdout → stdin between commands.
> overwrites; >> appends; < supplies stdin from a file.
2> is stderr; 2>&1 merges stderr into stdout (watch operator order).
Regex . [ ] * (and ? in the right mode) change matching — quote and escape when you mean literals.
With that plumbing solid, the extract tools in the next section become short, readable pipelines instead of one-off memorization.