What happens when we write “ls *.c”?

Julian Torres
3 min readJun 8, 2020

The first step in understanding the behavior of this is to understand the function of the ls command.

The ls command (short for list) lists the contents of directories and files. When you run ls without options, a list of contents of the current working directory is displayed.

Therefore, executing ls we would get:

Once the command is executed, bash returns to the prompt(is the character or set of characters displayed on a command line to indicate that it is waiting for commands).
This prompt is stored in the PS1 environment variable, this variable simply contains the string of our prompt.

But how does “*” work?

The asterisk (*) is a comodin that represents all possible files, this means that “ls *.c” would list all files with the extension “.c” as follows:

To shorten this command we could use an alias.

How the alias works?
Can be created simply by assigning a value or name to another order.

alias list="ls *c"

This alias causes that when the listc command is executed it will be replaced by “ls *c” therefore it will bring us the list of files with the extension .c, so:

Another way we could use would be an expansion.

What are expansions?
Is the substitution of a variable with its value, like this:

A="ls *c"
echo $A

The result would be the next:

the shell first looks at aliases before looking at commands and commands built into path. also note that the first word of a command is a built-in before checking for a program in the PATH.

But what is PATH?
is an environment variable in it specify the paths in which the command interpreter must look for the programs to run. With this we conclude that the Shell first examines aliases before commands and commands built into PATH.
The first word of a command is a built-in function before searching for a program in PATH.
In conclusion, PATH contains all executable paths.

--

--