What happens when you type ls *.c

More screens != better programming

The gist

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

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).

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store