Linux - the ls command and the *.c pattern
The purpose of this article is to explain what the ls *.c command does when the user types it and hit enter in the terminal. But first, it is important to understand what a command is and the difference between terminal, console and shell.
A command is a specific instruction given to a computer application to perform some kind of task or function. Commands must always be entered into a command line interpreter exactly. Entering a command incorrectly (wrong syntax, misspelling, etc.) could cause the command to fail or worse, could execute the wrong command or the right command in the wrong way, creating serious problems.
Other important concepts to understand are terminal, console, shell and kernel. While learning Linux we get confused with the actual meaning of these terms, sometimes we mix up their usage which is technically incorrect so having a clear grasp of what every word actually means and how and where they should be used is very important.
To explain the full ls *.c command line, we are going to break this line in 2 parts. first, we have ls which is one of the basic commands that any Linux user should know. For example, when the user types ls in the terminal and hit enter, the terminal shows all files and directories that are within the file system. For example, in the picture below, the user has entered the ls command and the terminal shows a total of 36 files within the current directory.
The second part of the code is the *.c pattern, which is a way of telling the command ls to list only the files that have a .c extension, which are usually C source code files. In the second picture, the user has entered the full command line ls *.c, and it can be seen that only files with .c extension are shown in the terminal.
Another brief example, if the user has a directory that contains the following files:
Then, using ls *.c will show only the first two files:
In summary, this can be helpful if the user wants to see only the C files in a directory and avoid getting distracted by other files or directories.
It is also possible to use other options with ls to customize the output.?For example, using -l will show you the files in a long listing format, which includes information such as file permissions, owner, group, size, date, and time.?Using -a will show you all files, including hidden ones that start with a dot.?Using -h will make the file sizes human-readable. You can combine multiple options together, such as ls -lah *.c to see all the details of the C files in a human-friendly way.
Bibliography:
Fisher, Tim. What is a Command for Computers. July, 2023. Link: What Is a Command for Computers? (lifewire.com)
What is a terminal, Console, Shell and Kernel. October, 2020. Link: What is Terminal, Console, Shell and Kernel? - GeeksforGeeks