*) is a powerful wildcard used in Unix-like shells and many programming languages to match any sequence of characters (including none). In file path patterns (globs), it lets you flexibly select files based on prefixes, extensions, or arbitrary substrings.
By mastering * you can streamline file operations, automate tasks in scripts, and improve your command-line efficiency.
How * Works
*matches zero or more characters in a filename or path segment.- It does not match the path separator (
/) unless the shell supports recursive globs (e.g.,**in Bash). - Always quote globs when you need to pass the literal pattern to a command rather than having the shell expand it first.
Prevent premature expansion by the shell. For example:Here,
grep receives the pattern *.txt instead of the shell expanding it.1. Matching Files with a Common Prefix
Imagine a directory containing:report. and any extension:
report.is matched literally.*covers any extension (including an empty extension if it existed).
2. Matching a Specific Extension
Given files:*matches any filename prefix..pdffilters for that exact extension.
3. Matching a Prefix with Varying Suffixes
In a directory like:image regardless of extension:
imageis the fixed prefix.*grabs everything that follows, covering.jpg,.jpeg,.png, etc.
Common * Patterns at a Glance
| Pattern | Description | Example Result |
|---|---|---|
report.* | Files starting with report. | report.txt, report.pdf |
*.pdf | Files ending in .pdf | notes.pdf, config.pdf |
image* | Files starting with image | image1.jpg, image2.jpeg |
* | All files in the current directory | Every visible file |