What happens when you type ls *.c — A Guide

For those unfamiliar with the terminal, even a seemingly simple command looks pretty alien. There’s no denying the language barrier between the few fluent in computer and those who aspire to be. There lay specific skills necessary to understand quintessential tools from the software engineer’s toolbox that need learning to flourish in your profession.

One of the most broad utilities is effectively using the computer via the shell, which is run via Terminal or Command Line.

So, what happens when you type a command like ls *.c ?

The first thing that you typed was ls, which read the file out onto a page and read the list of files in that directory that followed the pattern that follows, in this case *.c . Usually this is patternless in normal use, but this command will search for a specific pattern the file name needs to match with to print.

* The star is code for ‘any character’ will expand to whatever fills space between the beginning of the name or become nothing at all, letting ‘.c’ take up the space on the other side.

The resulting files printed all end in ‘.c’ because it was any file that the star ‘*’ matched with and the .c was the only required part to find.

This action taken by the bash command language means that the computer never even sees the star to output in the result because the language automatically converts it to every file that follows with ‘.c.’ Fairly simple, huh? Maybe bash isn’t such a bad thing :-)