Linux 101 : Bash wildcards and metacharacters

In Linux, we could use wildcards when working with the names of the files.

Below are some of the wildcards:

"*" : it matches any number of characters - zero or more -.

"?" : This matches any single character.

"[ ]" : it matches one or more of the characters that are in the brackets.

Metacharacters are as follows:

">" : redirection of output. The below example writes to the beginning of a file and overwrites its contents:

">>" : redirects output and appends it to the end of a file for example.

"<" : redirection of input. In the below example, the "cat" command displays the content of the file "file":

A complete example with "input" and "output" could be:

"<<" : Input redirection. For example the below command takes input until we enter EOF.

"|" : When using multiple commands, the output of one is the input of the other:

";" : sequence of command:

"command &" : to run a command in the background, so we would have access to the command line prompt instead of waiting for the command to exit.

• "$(cmd)" : runs a command substitution. The below command displays "username is root" if we are logged in as root.

• "{...,...,...,...}" : Brace expansion is as follows, we could use it as in the below example to remove three files in one command - file1, file2 and file3 -:


Leave as a comment: