What happens when you type ls *.c
To start to explain what we get when we input this command, lets ask what we’re trying to achieve. If you’re trying to list all files ending in .c, you’re in luck! We start up our terminal, fire up an ssh and we’re off!
But how exactly are we going about this? Well, for starters, we’re using the ls command. This command, called list, does just that; it makes a list of any files you want. To do so we simply type in the letters ls in a terminal and press enter. But in this case that’s not good enough, we want more, we want specific results, we want to see all files that end in .c so what could we add to help us search for every file that meets a certain criteria? In comes the second, weirder part of our script: the wildcard.
Wildcard (or *) is a command that quite simply represents all of something. It is an expansion. When combined to an extension, for example .c, we are saying “Hey computer, show me everything that matches this thing I’m looking for [.c]. The computer takes your input, does computery things and out comes a list of every file that matches your query. Congrats!
The computery things
Let’s dive deeper. How exactly does an input of arbitrary characters such as ls and * turn into a readable, intuitive result? The answer is through un-intuitive, low-level means.
First, an alias expansion occurs. What this means is that the computer searches for any aliases (i.e. commands hiding behind different names), and if it finds one it’ll search deeper for more aliases. Once it reaches it’s conclusion it moves on to the meat and potatoes: commands. It will find our desired command, in this case ls, perform it and return a result (output).