Lesson 3.5: Wildcards and path expansion
Let the shell fill in file names: * ? and [ ] match existing files (globbing), { } builds lists of words, ~ expands to your home; preview any pattern with echo before using it with rm.
15 min
You will learn to
- Match files with *, ? and [ ]
- Build lists with {a,b} and {1..5}
- Explain that the shell expands patterns before the command runs
- Preview a pattern with echo or ls before rm
Key terms
- Wildcard (glob)
- A special character in a name pattern that the shell replaces with the matching file names.
- * (star)
- Matches any number of characters, including none. Doesn't match the / between directories or a leading dot.
- ? (question mark)
- Matches exactly one character.
- [ ] (character set)
- Matches one character from the list or range inside.
- Brace expansion { }
- Writes out a list of words from comma-separated parts or a range, whether or not such files exist.
- Expansion happens first
- The shell replaces patterns before the command runs; the program only sees the final list of names.
← Spaces in paths and file names · All lessons · More ways to look at text: head, tail, wc, sort and uniq →