Unix Tutorial 6 : Special Characters or Metacharacters for File Manipulation
Unix Filename Wildcards – Metacharacters
#1) ‘*’ – any number of characters:
This wild-card selects all the files that matches 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 matches 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 matches 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 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]*
Comments
Post a Comment