Explore wildcard characters in filenames?

QuestionsQuestions8 SkillsProDec, 23 2025
0117

Wildcards are powerful characters that act as placeholders, allowing you to perform operations on groups of files that match a specific pattern. In Linux, the shell expands these wildcards before running the command.

Here are the most common wildcard characters you can use with commands like ls, touch, or rm:

1. The Asterisk (*) - Matches Zero or More Characters

This is the most common wildcard. It matches anything.

  • List all .txt files:
    ls *.txt
  • List everything starting with "ex":
    ls ex*

2. The Question Mark (?) - Matches Exactly One Character

Use this when you know the character count but not the specific character.

  • Match file1.txt, file2.txt, but not file10.txt:
    ls file?.txt

3. Square Brackets ([]) - Matches a Character Set

Use this to match any one character from a specific list or range.

  • Match filea.txt or fileb.txt:
    ls file[ab].txt
  • Match a range (e.g., any file ending in a digit 1 through 3):
    ls file[1-3].txt

Try it out in your project directory:

If you have example.txt from the previous step, try creating a few more files to experiment:

touch test1.txt test2.txt testA.txt
ls test[0-9].txt

This will show only test1.txt and test2.txt, filtering out testA.txt.

Wildcards make managing large numbers of files much faster! Do you want to try applying this to the permissions we are learning about?

0 Comments

no data
Be the first to share your comment!