Login Register
The stories and information posted here are artistic works of fiction and falsehood. Only a fool would take anything posted here as fact.


Tutorial Wildcard Characters filter_list
Author
Message
Wildcard Characters #1
A wildcard, is a character that represents a string of any characters or a single character. The reason it's called a wildcard, is because any character can be assigned to it.

There are different wildcards in Linux, namely the Star (*), the Question Mark (?), and the Square Brackets ([]). They each work differently, as is explained below.

The Star Wildcard

This character is the most common, and also the one with the broadest meaning. It can represent a string of any characters, a single character, or even zero characters.

For example:

Code:
cat *.txt
This would display the output of all text files in the current directory.

Code:
rm *
This would remove all files and folders in the current directory.

Code:
ls *lel*.*
This would display all the files in the directory that have the string 'lel', and any file extension.

The Question Mark Wildcard

The question mark wildcard is similar to the star wildcard, but it only represents any single character.

For example:

Code:
ls ?????.???
This would list all files in the current directory that have a five-character name and a three-character file extension.

Code:
rm ??*
This would delete all files in the current directory that have two or more characters in the name.

Code:
oni-is-???
This would represent any string starting with 'oni-is-' followed by any three characters.

The Square Brackets Wildcard

This type of wildcard represents of the characters enclosed in the brackets. Optionally, hyphens can be added to declare ranges.

For example:

Code:
*[sex]*
This represents any string containing an 's', an 'e', or an 'x'.

Code:
[a-z0-9]
This represents any lowercase alphanumeric character.

Code:
[abc]*.*
This represents any file starting with an 'a', a 'b', or a 'c'.

You can string multiple square brackets together like so:

Code:
*.[a-z][a-z][a-z]
This represents any file with a three letter alphabetical file extension.

Hope you learned something,
Eclipse

Reply







Users browsing this thread: