Back to course

26. Utilizing Wildcards and Globbing (`*`, `?`)

Linux Basics: From Zero to CLI Hero

Selecting Multiple Targets

Wildcards, or globbing, are special characters used to represent patterns in filenames or paths. They allow you to operate on multiple files with a single command.

The Asterisk (*)

The asterisk matches zero or more characters in a filename.

  1. Match all files: bash $ ls *

    Lists everything in the current directory

  2. Match files with specific extension: bash $ cp *.txt backup/

    Copies all files ending in .txt to backup/

  3. Match files starting with a prefix: bash $ rm log_*.bak

    Removes all files starting with 'log_' and ending in '.bak'

The Question Mark (?)

The question mark matches exactly one character.

bash $ ls file?.txt

Matches file1.txt, fileA.txt, fileZ.txt, but NOT file10.txt