Shell wildcards

A wildcard is a character that can replace one or more characters. Linux uses 3 wildcards:

  • star (*) – substitutes zero or more characters
  • questions mark (?) – matches a single character
  • square brackets ([]) – represents any of the characters enclosed in the brackets

These wildcards are mainly used when specifying file names or paths.

One nice trick is you can use wildcards to also run Linux utilities. Let’s take head for example. head is a command-line utility for outputting the first part of files given to it via standard input

head text

is the same as running

/usr/bin/head text

However, using wildcards we can run the following command:

/?s?/b*/h*ad t?xt

and we’d get the beginning of the text file

This is mostly used when you need to run specific commands, but you can only use a limited set of characters or you encounter a validator that rejects certain words (cat, tail, head, bin, usr etc)

Leave a Reply

Your email address will not be published.

Secured By miniOrange