ls *.c function in Linux

ls command is one of the most frequently used Command in Linux. I believe that it’s the first command any beginner may use when he get into the prompt of Linux Box. We use ls command daily basis and frequently even though we may not aware and never use all the ls option available. In this article, we’ll be discussing only one of many uses of ls.

ls *.c:

Let’s decompose this command into twosections:

First section ls: ls is a Linux shell command that lists directory contents of files and directories.

Second section “*.c”: the “*” is a wildcard (A wildcardin Linux is a symbol or a set of symbols that stands in for other characters. It can be used to substitute for any other character or characters in a string.) that matches any character or set of characters, including no character. Example : A*c matches anything that begins with A and ends with c (like Ainc, Akhc, Aerc, Aereec, Aac, Aerererc, Ac, Aarmeerrc). The number of characters in between O and d is not important. And in our case “*.c” this wildcard will match Any file that have the expansion .c .

That’s individually and simply what happens but exactly this what happens:

The shell reads the command ls *.c from the getline() function’s STDIN, parsing the command line into arguments that it is passing to the program it is executing. The shell checks if ls is an alias. If it is, the alias replaces ls with its value. If ls isn’t an alias, the shell checks if the word of a command is a built-in. Then, the shell looks for a program file called ls where all the executable files are in the system — in the shell’s environment (an array of strings), specifically in the $PATH variable. $PATH, one of the environment variables, is parsed using the ‘=’ as a delimiter. Once the $PATH is identified, all the directories in $PATH are tokenized, parsed further using ‘:’ as a delimiter.

Conclusion:

The shell will list all files that ends with .c .

--

--

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