Step by Step, Command ls *.c
This blog post describing step by step what happens when you type ls *.c
and hit Enter in a shell.
Let’s start with where to write the command, On linux and unix systems the way used to send orders to the system is called prompt, it is a text string that indicates information such as the username, the current directory and sometimes the machine, This line ends with a character “$”, “#” and after this it waits for commands. you can see some examples in image 2.
After write the command at the prompt, it is interpreted by the shell. The shell reads the command then parses the command with the arguments and executes the command.
The shell checks if ls is an alias. If so, the alias replaces ls with its value. If ls is not an alias, the shell checks to see if the word in a command is a built-in one in its library. The shell finds the ls function in system executable files.
Let’s move on to interpreting the instructions, shell finds ls as an executable file to list the contents of a directory or directories given to it through standard input (see image 3). Write the results to standard output. The ls command allows you to display a variety of information about files, sort on a variety of options, and recursive lists.
But… wait a minute our instruccion is ls *.c
Okay, we already know that we are going to list directories or files, but what about the ls companions, let’s see.
(*) the asterisk is a wildcards (especial characters, see Image 4), that makes the command so powerful and help you rapidly specify groups of filenames. TIts like a to select filenames based on patterns of characters.
For example, if you enter ale* as the search term, the search can return these items:
ale
ale1
alehiguera1.txt
You can use wildcard search on the command line to list all files with a particular extension. For example, if you want to find all files that end with .txt
Now we have it, let’s break it down…
- write our command, instruction
- find ls, which gives us a list of files and directories
- the *, select some files or directories from our list.
- .c, specify the selection
In conclusion, our instruction is list the contents of my directory, select the files ending in .c and only show me that selection, as you can see in our image 1. after the instruction the output is file1.c and file2.c .
reference