Wildcards in Linux

Wildcards are a set of building blocks that allow you to create a pattern defining a set of files or directories.


Here is the basic set of wildcards:
  • * - represents zero or more characters
  • ? - represents a single character
  • [] - represents a range of characters

 Wildcards may be used with any command.

  •  *
It represents zero or more characters. If you want to list all the files and directories then this wildcard is very benefitial.In simple words, whenever you use * means it will include all the character.

ls * 
E.g.  if you want to list all the directory which starts with D. Then you just have to write.

ls D*
it will list all the directories and files of those directories which starts with D.
example of *


suppose you want to search all files with extension png.

ls path *.png

Here path is from where you want to list all png.
search file type

  • ? -
it represents one character. This wildcard is used as a filter like if you want to search a directory whose second letter is o or whose extension is of 3 words.. etc. It is mainly used with * wildcard.
Example screenshot


it means list all the file whose first letter is unknown but second character is o and i do not care about remaining characters in the file name.

Example screenshot

it means i do not care about file name. i care about extension only whose length consists of 3 characters.

  • [] -
It represents range of characters. so, it is also called range operator.
suppose you want to see all files or folders whose name starts with M, V and f.
Example Screenshot

or you want to list all files which is in range between A-F.

Example Screenshot


i guess you got the basic understanding about wildcard.


Related Posts Plugin for WordPress, Blogger...