Skip to main content
When working in the shell, special characters like ?, *, and [ ] are interpreted by the globbing engine for filename matching. Preceding these characters with a backslash (\) or quoting them forces the shell to treat them as literal characters.
Using an escape (\) or quotes disables globbing for the next character or entire string. This gives you precise control over filename creation and listing.

1. Creating Sample Files

First, generate files whose names differ only by the first letter:

2. Wildcard vs. Literal ?

2.1 Using the ? Wildcard

The ? matches exactly one character. Attempting to create ?ail without escaping:
No new file appears because ?ail expanded to all existing matches (fail, hail, etc.).

2.2 Escaping ? for Literal Filenames

To create a file literally named ?ail:

3. Listing Files with a Leading ?

You can retrieve the ?ail file by escaping or quoting the pattern:
Both methods disable globbing and match the literal filename.

4. Mixing Literals and Wildcards

Assume these files exist:
To list all files starting with a literal ?ail:
Here, \?ail* treats \? as literal ? and * as the wildcard for any suffix.
Be cautious: unescaped wildcards can match unintended files. Always check your patterns with echo or ls before running destructive commands.

5. Merging Globs into a Single Pattern

For files named Pail, Pail*, and PailTwo:
You can match them all using:
The * wildcard expands to zero or more characters following Pail.

6. Quick Reference Table

Summary

  • A backslash (\) or quotes disables globbing for the next character or entire string.
  • Use wildcards (?, *, [ ]) without escaping to match patterns.
  • Combine escaped literals and wildcards for precise filename operations.

Watch Video