Core Utilities
GNU Coreutils Overview
Section titled “GNU Coreutils Overview”GNU coreutils is the package that provides the fundamental file, shell, and text manipulation Utilities on virtually every Linux distribution. These utilities implement the POSIX specifications and extend them with GNU-specific options. The package contains roughly 105 programs, grouped into:
- File utilities: ls, cp, mv, rm, ln, chmod, chown, touch, mkdir, rmdir stat, du, df, sync
- Text utilities: cat, head, tail, sort, uniq, tr, cut, paste, join, wc nl, fmt, fold, pr
- Shell utilities: echo, printf, date, tee, basename, dirname, sleep, true false, test, expr, yes, timeout
Text Processing Pipeline Patterns
Section titled “Text Processing Pipeline Patterns”The Unix philosophy of composing small, single-purpose tools into pipelines is the foundation of Linux systems administration. Understanding how to chain these tools effectively is a core Competency.
grepPattern Matching
Section titled “grepPattern Matching”grep searches input lines for patterns matching a regular expression and prints matching lines. Three main variants exist:
| Variant | Regex Flavor | Description |
|---|---|---|
| grep | BRE | Basic Regular Expressions (default) |
| grep -E | ERE | Extended Regular Expressions |
| grep -P | PCRE | Perl-Compatible Regular Expressions |
bash
Basic pattern matching
Section titled “Basic pattern matching”grep “error” /var/log/syslog
Case-insensitive
Section titled “Case-insensitive”grep -i “warning” /var/log/syslog
Invert match (lines that do NOT match)
Section titled “Invert match (lines that do NOT match)”grep -v “debug” /var/log/syslog
Show line numbers
Section titled “Show line numbers”grep -n “error” /var/log/syslog
Count matches
Section titled “Count matches”grep -c “error” /var/log/syslog
Show only matching portion
Section titled “Show only matching portion”grep -o “error:[0-9]*” /var/log/syslog
Recursive search through directories
Section titled “Recursive search through directories”grep -r “TODO” —include=“*.py” src/
Context lines (2 before, 2 after)
Section titled “Context lines (2 before, 2 after)”grep -C 2 “panic” /var/log/kern.log
Extended regex (alternation, quantifiers without escaping)
Section titled “Extended regex (alternation, quantifiers without escaping)”grep -E “error|warning|critical” /var/log/syslog
PCRE, lookahead, lookbehind, non-greedy quantifiers
Section titled “PCRE, lookahead, lookbehind, non-greedy quantifiers”grep -P ”(?<=status: )\d{3}” response.txt
Fixed string (no regex interpretation)
Section titled “Fixed string (no regex interpretation)”grep -F “file.name” search.log
Color output
Section titled “Color output”grep —color=always “pattern” file
BRE vs ERE vs PCRE
Section titled “BRE vs ERE vs PCRE”| Feature | BRE | ERE | PCRE |
|---|---|---|---|
| Literal match | abc | abc | abc |
| Any character | . | . | . |
| Zero or more | * | * | * |
| One or more | {1,} | + | + |
| Zero or one | ? | ? | ? |
| Alternation | | | | | | |
| Grouping | () | () | () |
| Character class | [abc] | [abc] | [abc] |
| Lookahead | No | No | (?=…) |
| Lookbehind | No | No | (?<=…) |
| Non-capturing group | No | No | (?:…) |
| Named capture | No | No | (?P<name>…) |
| Backreference | \1 | \1 | \1 or \k<name> |
| Unicode properties | No | No | \p{L} |