What happens when you type `ls -l *.c` in the shell.

Caroline
2 min readApr 9, 2021

When the command is entered, the first thing the program does is parse through the command entered and separate the command from the options into a 2D array. Once the command is extracted, the program searches for the command in the PATH. The PATH details all the files in the specific environment you are in that contains the executable files for your shell commands.

The first part of the command is:

ls

The shell looks for ls in the PATH. Once it finds the binary file, it runs it. This specific command ls, list all of the files in the current working directory.

The next part of the command is:

-l

The ls command can be used with various command options. For example:

ls -a

As you can see in the snippet from the ls man page above, the -a option does not ignores files that start with a period. The ls executable file, just like many other commands, accept the options as parameters, in the format of a 2D array.

The -l displays the files in the “long list” format. Below you can see difference between ls and ls -l.

The final part of the command is:

*.c

What this option does, is restrict all the content about to be listed in the terminal to everything that ends with .c. The * wildcard characters represents anything that comes before the “.c”. Here is an example of everything put into action:

--

--

Caroline
0 Followers

Holberton School Programming Student