What happens when you type `ls *.c` into your shell?
Let’s start from the scratch. What is the shell?
Simply put, the shell is a program that takes commands from the keyboard and gives them to the operating system to perform. In the old days, it was the only user interface available on a Unix-like system such as Linux.
A Linux console terminal is one of the system consoles provided in the Linux kernel. The Linux console terminal acts as the medium for input and output operations for a Linux system
Within the system, information is stored in directories, sub-directories and individual files.
What happens when we type ls?
The ls command is one of the basic commands that any Linux user should know. It is used to list information about files and directories within the file system. The ls utility is a part of the GNU core utilities package which is installed on all Linux distributions.
So by typing in [ls] and hitting [Enter], you get:
So by typing in [ls] and hitting [Enter], you get a list of the files within the current working directory:
Now, Unix commands can be refined on what they do (their functionality) using options or wildcards. In this case, we want to list (output) all files and directories (within our current directory) with the filename extension “.c” by using the “ * ” [asterisk] wildcard.
So, step by step:
1. ls command lists files and directories.
2. “*” is a wildcard character that can be used as a substitute for an array of characters in a search.
4. “*” can be used with strings or characters/symbols to refine or modify parameters of a search.
5. ls *(string) will result in finding any and all files with the string pattern at the ending of the filename. Vice-versa if we do it ls (string)* it will search for the string pattern at the beginning of the filename.
6. ls *.c will try to list all files with the .c extension, if no files are found the command line output prompt will be something like this “ls: cannot access *.c: No such file or directory”. In the example we have been using, the output will be this: