What happens when you type ls *.c ?

Ana-Morales
2 min readJun 8, 2020

Expansion is done on the command line after it has been broken into tokens. There are diferent kinds of expansions, this time I am gonig to talk abour Filename Expansion (or Pathname expansión).

Filename expansión is a shorthand for specifying filenames matching patterns. When you write an argument in the command line, Bash scans each word for the special characters ‘ * ’, ‘ ¿ ’ or ‘ [ ‘, these characters are also known as wildcards. If any of these characters appears, the word is considered a pattern ( see Pattern Matching) and is replaced by an alphabetical list of filenames that match the pattern. Then the list is passed to the program called by the command line. Let’s see an example.

Example:

When you type the following on the command line:

ls *.c

The shell expands the ‘*.c’ argument and lists all files in the working directory which names ends with the string ‘.c’. The the Shell passes the list to ls command.

For more info about Shell expansion check these links:

Shell Expansion

Filename Expansion

Pattern Matching

Filename Generation/Pathname Expansion

--

--