Skip to main content

Filename Patterns

Linux and Windows systems both allow ambiguous filenames (or filename patterns), which use wildcard symbols to enable filename matching. The process of converting an ambiguous filename, or filename pattern, into a list of matching filenames is called globbing or filename expansion.

On a Linux system, globbing is performed by the shell. This means that all arguments are subject to globbing, whether they're intended to be a filename argument or not.

On a Windows system, ambiguous filenames are converted into a list of filenames by the command or application. This means that arguments that are not filenames are not subject to filename expansion. However, it also means that applications must contain additional code to perform globbing.

Wildcard Symbols

SymbolMeaning in LinuxMeaning in Windows
*Matches zero or more charactersMatches zero or more characters
?Matches one characterMatches one character, unless at the end of the filename or immediately before the dot preceeding the extension in which case it matches zero or one character
[list] or [range]Matches any one of the characters within the brackets (note that it matches exactly one of the characters)Not applicable

Examples

PatternMatches on LinuxDoes not match on LinuxMatches on WindowsDoes not match on Windows
*.htmlfirst.html blue.htmlRED.HTML purple.htmBlue.html blue.html RED.HTMLpurple.htm
a*a aa aaa alpha argonautAlpha bananaa aa aaa alpha Alphabanana
b*eblue bitered green blotblue bitered green blot
c[oa]tcat cotcoatcat cot coat //(Not applicable)//
d?edue doeduo Doe datedue doe Doeduo date
a??aaa abcaa abcdaaa abc aaabcd

Therefore the command

del *.pdf

on Windows, or

rm *.pdf

on Linux will remove all files in the current directory that have the extension .pdf

You can combine absolute, relative, or relative-to-home pathnames with patterns. For example, in the command:

 del \Users\jdoe\Documents\*.txt

the pattern \\Users\\jdoe\\Documents\\\*.txt* will match all files with a txt extension in the \\Users\\jdoe\\Documents\\ directory, and the del command will then attempt to delete all of the matching files.

On Linux, you can also use patterns to match directory names:

 rm /home/chris/ops102/*/info.pdf

This will delete any files named info.pdf within any subdirectory of /home/chris/ops102/