Unix Special Characters or Metacharacters for File Manipulation

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated March 9, 2024

Overview of Unix Filename Wildcards or Special Characters or Metacharacters:

In this tutorial, we will learn to use wildcards to specify and select multiple files for commands that manipulate files.

Filename wildcards, which is also known as metacharacters, is a very helpful feature. 

Unix Special Characters or Metacharacters for File Manipulation

Unix Video #9:

Unix Filename Wildcards – Metacharacters

#1) ‘*’ – any number of characters:

This wild card selects all the files that match the expression by replacing the asterisk-mark with any set of zero or more characters.

  • Example1: List all files that start with the name ‘file’. g. file, file1, file2, filenew
    • $ ls file*
  • Example2: List all files that end with the name ‘file’. g. file, afile, bfile, newfile
    • $ ls *file

#2) ‘?’ – single character:

This wild-card selects all the files that match the expression by replacing the question mark with any one character.

  • Example1: List all files that have one character after ‘file’. g. file1, file2, filea
    • $ ls file?
  • Example2: List all files that have two characters before ‘file’. g. dofile, tofile, a1file
    • $ ls ??file

#3) ‘[’ range ‘]’ – single character from a range:

This wild-card selects all the files that match the expression by replacing the marked range with any one character in the range.

  • Example1: List all files that have a single digit after ‘file’. g. file1, file2
    • $ ls file[0-9]
  • Example2: List all files that have anyone’s letter before ‘file’. g. afile, zfile
    • $ ls [a-z]file

# 4) ‘[’ range ‘]*’ – multiple characters from a range:

This wild-card selects all the files that matches the expression by replacing the marked range with one or more characters from the range.

  • Example1: List all files that have digits after ‘file’. g. file1, file2, file33
    • $ ls file[0-9]*

Enjoy the video!!

PREV Tutorial | NEXT Tutorial

Was this helpful?

Thanks for your feedback!

Leave a Comment