Fundamentals 6 min read

Master Linux Shell Wildcards: How * and ? Really Work

This article explains Linux shell wildcard behavior, demonstrates common patterns with practical examples, clarifies the difference between wildcards, meta characters, and escape sequences, and outlines the shell's parsing steps, helping readers avoid common pitfalls when using * , ?, [] and {} in commands.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux Shell Wildcards: How * and ? Really Work

Linux Shell Wildcards (Wildcard)

Wildcards are processed by the shell, not by the individual commands. When a wildcard appears in a command’s arguments, the shell expands it to matching file names on the filesystem; if no match is found, the pattern is passed unchanged to the command.

Example:

[chengmo@localhost ~/shell]$ ls a.txt b.txt c.old

In the second command, *.txt matches a.txt and b.txt, so the command actually executed is ls a.txt b.txt. In the third command, d*.txt finds no matches, so the literal string d*.txt is passed to ls, resulting in an “cannot access” error.

Common Shell Wildcards

The most frequently used wildcards are *, ?, [], and {}. They resemble regular expressions but operate differently and should not be confused.

Shell Meta Characters

Meta characters are special symbols that the shell interprets before passing arguments to commands. They include operators such as |, &, ;, ( ), < >, and whitespace. These characters control command flow rather than file matching.

Shell Escape Characters

To treat a wildcard or meta character as a literal, you can use one of three quoting mechanisms: the escape character ( \), single quotes, or double quotes.

Example with escaping: [chengmo@localhost ~/shell]$ ls '*'.txt The asterisk loses its wildcard meaning and is treated as a literal character.

Shell Command Parsing Process

The shell processes a command in several steps: tokenization, expansion (parameter, command, arithmetic), and finally execution. Quoting influences which steps are performed. Double quotes allow parameter, command, and arithmetic expansion; single quotes skip all expansions.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxwildcardescapingCommand parsingMeta characters
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.