Understanding Globbing in Linux: A Simple Guide

If you’ve ever used the Linux terminal, you’ve likely seen symbols like *, ?, or [] inside commands. These aren’t random characters — they’re part of a powerful pattern-matching system called globbing.

What Exactly Is Globbing?

Globbing helps you match multiple files at once without typing every filename manually. It’s fast, efficient, and built directly into the shell.

Globbing is the shell’s way of expanding wildcard patterns into filenames. Instead of writing long lists of files, you can use patterns to match groups automatically.

For example:

ls *.txt

This lists all .txt files in the directory — no extra steps needed.

Common Globbing Patterns

Here are the patterns you’ll use most:

  • * (asterisk) – matches any number of characters
  • rm *.log → deletes files ending in .log
  • ? (question mark) – matches exactly one character
  • ls file?.txt → matches file1.txt, fileA.txt, etc.
  • – match a set or range
  • ls photo[1-5].jpg → matches photo1.jpg to photo5.jpg
  • ls file[abc].txt → matches filea.txt, fileb.txt, filec.txt

Brace Expansion: Not Globbing, But Useful

You might see people use braces like {}:

mkdir {2024..2026}

This creates 2024, 2025, and 2026.
It looks similar to globbing, but it’s actually handled before globbing by the shell.

Why Globbing Matters

Globbing speeds up your workflow by allowing the shell to handle pattern matching for you. Instead of typing dozens of filenames or crafting complicated scripts, you can control groups of files using just a few characters.

It’s an essential skill for:

  • developers
  • sysadmins
  • automation scripts
  • anyone working heavily in the terminal

Try It Yourself

Open your terminal and test:

touch test1.txt test2.txt test3.log
ls *.txt
ls test?.*
ls test[1-2].txt

You’ll instantly see how globbing expands your patterns into real filenames.

Leave a Comment