Linux Shell Help and Glob Patterns
- Description: How to read built-in help on Linux (
man,info,whatis,--help,apropos,tldr) and how shells expand glob patterns — wildcards, character classes, brace expansion — plus how globs differ from regular expressions. - My Notion Note ID: K2B-3-1
- Created: 2020-06-03
- Updated: 2026-05-19
- License: Reuse is very welcome. Please credit Yu Zhang and link back to the original on yuzhang.io
Table of Contents
- 1. Reading the Help System
- 2. Conventions in Synopsis Lines
- 3. Navigating
man - 4. Navigating
info - 5. Shell Globs vs Regex
- 6. Glob Syntax
- 7. References
1. Reading the Help System
- Four+ tiers, in order of increasing depth:
whatis <cmd>→ one-line summary from the man database. Fastest sniff.<cmd> --help/<cmd> -h→ usage block printed by the program itself. Variable quality; some tools (ls,grep) have rich--help; minimal tools have none.man <cmd>→ full manual page. The default deep reference on Unix.info <cmd>→ GNU Texinfo manual — longer-form, hyperlinked, used by GNU coreutils/binutils. Often more detailed thanmanfor those tools.
- Auxiliary:
apropos <keyword>→ search thewhatisdatabase by keyword. Same asman -k. Use when you can't remember the command name.type <cmd>/which <cmd>→ tells you whether a name is a builtin, alias, function, or external binary, and where the binary lives.help <builtin>→ shell builtin docs (Bash).man bashcovers them too but is huge.tldr <cmd>→ community-maintained example-first cheat sheets (separate install). Skips prose, shows common invocations.
2. Conventions in Synopsis Lines
Same convention across man, --help, and POSIX docs:
| Notation | Meaning |
|---|---|
[option] |
optional |
<replace> or ARG |
placeholder — substitute a real value |
| |
mutually exclusive choice |
... |
one or more (repeatable) |
[ARG]... |
zero or more |
- Example:
ls [OPTION]... [FILE]...→ both options and files are optional and may be repeated.
3. Navigating man
man <cmd>opens the manual in a pager (lessby default).- Inside the pager:
/keyword— forward search.?keyword— backward search.n/N— next / previous match.Space/b— page down / up.g/G— top / bottom.q— quit.
- Man sections (the number in
ls(1),open(2)):- 1 user commands
- 2 system calls (kernel API)
- 3 library functions (libc, libm, …)
- 5 file formats and configuration files (
man 5 passwd) - 7 miscellaneous (protocols, glob, regex)
- 8 sysadmin commands
- Disambiguate when a name lives in multiple sections:
man 2 openvsman 1 open. man -k <regex>≡apropos(search short descriptions).man -f <name>≡whatis(exact name match).
4. Navigating info
- GNU's hyperlinked manual format. Pages are organized as a tree of nodes.
- Key bindings:
PageUp/PageDown(orSpace/Backspace) — scroll within a node.Tab— jump to the next hyperlink.Enter— follow the hyperlink under the cursor.n/p— next / previous sibling node.u— up one level.t— top of the manual.s <keyword>— search across the whole manual.l— go back (like a browser).q— quit.
- Many GNU tools have a one-screen
manpage and a real manual underinfo(e.g.info coreutils 'ls invocation').
5. Shell Globs vs Regex
Three pattern languages that look similar but behave differently:
| Layer | Where | What it matches | Examples |
|---|---|---|---|
| Shell glob (a.k.a. wildcard) | shell expansion on filenames | filename patterns, no regex semantics | *.c, ??.txt, [abc]* |
| Regex (BRE / ERE) | grep, sed, awk |
string patterns | ^foo, a|b, (ab)+ |
| PCRE | grep -P, pcregrep, Perl, Python re |
richer regex (lookaround, lazy quantifiers, …) | (?<=foo)bar, \d+? |
- Pitfall —
*does not mean "any string" in glob the same way it does in regex. In glob,*matches any sequence of characters including the empty string, but only within a single path component (does not cross/unlessglobstar/**is enabled). In regex,*means "zero or more of the previous atom" — completely different. - The original
[Y]note's examplea*.b— under glob, that's "any filename starting withaand ending with.b" (e.g.a.b,abc.b,axyz.b). Under regex, it would mean "zero or moreas followed by any single character followed byb" — almost never what you want for filenames.
6. Glob Syntax
Standard POSIX glob (supported by Bash, Zsh, Fish, etc.):
| Pattern | Matches |
|---|---|
* |
any sequence of characters (within one path component) |
? |
exactly one character |
[abc] |
one character from the set |
[a-z] |
one character in the range |
[!abc] (or [^abc] in Bash/Zsh) |
one character not in the set |
Bash extensions (shopt -s extglob):
| Pattern | Matches |
|---|---|
?(p) |
zero or one occurrence of p |
*(p) |
zero or more |
+(p) |
one or more |
@(p1|p2) |
exactly one of the alternatives |
!(p) |
anything except p |
Brace expansion (a separate mechanism — happens before glob expansion, even when no file matches):
cp file.{txt,bak}→cp file.txt file.bakmkdir -p project/{src,test,docs}→ three subdirsecho {1..5}→1 2 3 4 5. Step:{1..10..2}→1 3 5 7 9.echo {a..c}{1..2}→a1 a2 b1 b2 c1 c2.
Recursive glob (**) — Bash needs shopt -s globstar, Zsh is on by default:
**/*.py→ every.pyfile anywhere under the current dir.
Hidden files:
*does not match leading-dot files (.bashrc,.git) by default. Use.*to include them, orshopt -s dotglobto make*match them.
7. References
man man,man 7 glob,man 7 regex- GNU coreutils manual — https://www.gnu.org/software/coreutils/manual/coreutils.html
- Bash Reference Manual, Pattern Matching — https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html
tldrpages — https://tldr.sh/- Runoob Linux command index — http://www.runoob.com/linux/linux-command-manual.html