Step by Step, Command ls *.c

Alejandra Higuera
3 min readSep 16, 2020


This blog post describing step by step what happens when you type ls *.cand hit Enter in a shell.

Image 1. Capture output of the command

Let’s start with where to write the command, On linux and unix systems the way used to send orders to the system is called prompt, it is a text string that indicates information such as the username, the current directory and sometimes the machine, This line ends with a character “$”, “#” and after this it waits for commands. you can see some examples in image 2.

Image 2. Prompt examples.

After write the command at the prompt, it is interpreted by the shell. The shell reads the command then parses the command with the arguments and executes the command.

The shell checks if ls is an alias. If so, the alias replaces ls with its value. If ls is not an alias, the shell checks to see if the word in a command is a built-in one in its library. The shell finds the ls function in system executable files.

Let’s move on to interpreting the instructions, shell finds ls as an executable file to list the contents of a directory or directories given to it through standard input (see image 3). Write the results to standard output. The ls command allows you to display a variety of information about files, sort on a variety of options, and recursive lists.

Image 3. ls output

But… wait a minute our instruccion is ls *.c

Okay, we already know that we are going to list directories or files, but what about the ls companions, let’s see.

Image 4. Wildcards

(*) the asterisk is a wildcards (especial characters, see Image 4), that makes the command so powerful and help you rapidly specify groups of filenames. TIts like a to select filenames based on patterns of characters.

For example, if you enter ale* as the search term, the search can return these items:


You can use wildcard search on the command line to list all files with a particular extension. For example, if you want to find all files that end with .txt

Now we have it, let’s break it down…

  1. write our command, instruction
  2. find ls, which gives us a list of files and directories
  3. the *, select some files or directories from our list.
  4. .c, specify the selection

In conclusion, our instruction is list the contents of my directory, select the files ending in .c and only show me that selection, as you can see in our image 1. after the instruction the output is file1.c and file2.c .