¿What happens when you type ls *.c ?

Katherine De La Hoz
2 min readSep 15, 2020
Command

Behind these 7 characters there is a great search. I can start by saying that the ls command lists the files and folders contained in the current directory. This command performs a path expansion that shows all the files and folders that this path contains.

When we type the ls command, the terminal shows all the files (in white) and folders (in blue) that this directory contains. If in addition to the ls command we add a * a broader search is carried out, the special character * searches for all the files and folders contained in the current directory and the folders and files contained in each one of them.

Now let’s see what happens when we press ls * .c. This query returns all files contained in the current directory with an extension (.c). For this to happen, bash must carry out some processes, one of them is to list all the files (ls *) with the entered extension (.c). But this not only happens with this extension, it is also possible to change the extension if that is what we need. What if what I need are files with the extension .js and not .c? What we would have to do in this case is to write the command like this: ls * .js.

In the same way we could do it with the different existing extensions. If there are no files with this extension, the terminal will show us the following message:
ls: cannot access * .c: file or directory does not exist

--

--