What happens if you type ls *.c and press enter in your linux shell?

Francisco Guzmán Herrera
2 min readJun 9, 2020

basically if you run this command in your linux terminal it will show you all the files that end with a “.c” extension. let’s understand how it works

this command “ls *.c” has 3 parts

  1. ls
  2. .c
  3. *

the command “ls” is one of the most used in the terminal of linux since this allows us to see the content found in a folder or directory, to use it, simply type ls in your Linux terminal and press enter.

If the directory is not empty you will see something like this:

As we see the first line was where we executed the ls command and the second one show the elements that our directory contains. (the third line is waiting for another command like the first before executing “ls”)

What is “.c” in the command?

We also see that the file named “happy” marked with yellow in the image is the only one without an extension. the file extension is the indicator of the type to which it belongs, for example the .txt extension of the hello.txt file indicates that it is a text file.

so we already know what “.c” means in our command is an extension that in this case refers to files of type C.

What is “*” in the command?

“*” is a metacharacter that substitutes any sequence of characters, that is, it can be both “tools” and “_news_of_today” can be any text, and if we put together “*.c” we are expressing any character sequence that ends with a “.c” extension.

Let’s execute ls *.c

Now that we understand the 3 parts of our command we can conclude that if we execute “ls * .c” it will show all the elements of a directory whose extension ends in “.c” regardless of what it is called.

Now, as we see in the fourth line, only are show the files with the extension “.c” at the end.

--

--