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``rmdirstat``du``df``sync - Text utilities:
cat``head``tail``sort``uniq``tr``cut``paste``join``wcnl``fmt``fold``pr - Shell utilities:
echo``printf``date``tee``basename``dirname``sleep``truefalse``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.
grep — Pattern Matching
Section titled “grep — Pattern 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 |
# Basic pattern matchinggrep "error" /var/log/syslog
# Case-insensitivegrep -i "warning" /var/log/syslog
# Invert match (lines that do NOT match)grep -v "debug" /var/log/syslog
# Show line numbersgrep -n "error" /var/log/syslog
# Count matchesgrep -c "error" /var/log/syslog
# Show only matching portiongrep -o "error:[0-9]*" /var/log/syslog
# Recursive search through directoriesgrep -r "TODO" --include="*.py" src/
# Context lines (2 before, 2 after)grep -C 2 "panic" /var/log/kern.log
# Extended regex (alternation, quantifiers without escaping)grep -E "error|warning|critical" /var/log/syslog
# PCRE — lookahead, lookbehind, non-greedy quantifiersgrep -P "(?<=status: )\d{3}" response.txt
# Fixed string (no regex interpretation)grep -F "file.name" search.log
# Color outputgrep --color=always "pattern" fileBRE 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} |