Introduction/Overview
Work at the command line could be quite tedious and repetitive without glob patterns.
In combination with good file and directory naming practices, these patterns allow you to operate on multiple files at a time instead of one file at a time. You just have to make sure those files share some features (e.g. they all start with sub, or all contain the number 12 etc.).
This 3-minute video introduces common glob patterns, like *
and ?
that can be used to operate on multiple files at once.
It focuses on the purpose of glob patterns, especially the star *
(sometimes called a splat), and the ?
. The star substitutes for any number of characters, whereas the ?
substitutes for a single character.
Glob Patterns: A Deeper Dive
In this 12-minute video, Tom Hicks discusses glob patterns and their use in more detail and provides examples using:
- the
*
(which matches 0 or more characters), ?
(which matches a single character),\
(which cancels the meaning of a special character, and[]
(which allows you to list alternatives).
These patterns are closely related to regular expressions.
Unix Commands
- My focus in Unix1 and Unix 2 is to teach you commands for viewing, navigating, creating, and removing files and directories. These are critical!
- Unix Commands Cheatsheet
- To use these commands, you must also understand the context in which they are used: You need to understand the directory tree and permissions.
- Globbing, especially understanding how to use
*
, will save you a lot of time.
Resources
Optional practice is available as a Google Cloud Shell tutorial tutorial_02_unix_file_manipulation.md:
- Start the tutorial by typing
Digest
Stop and think about these special globbing characters
? Match a single character
[a,b] Use braces to match a or b
\ Use backslash to cancel the special meaning of a character