Luigi Arrieta
3 min readNov 14, 2020

--

What happens when you type ls *.c

command ls *.c

You remember which was the first command you learned in linux, for sure ls is within those first commands. ls is a very used command by linux users and like other linux commands we can do wonderful things with it. join me to see what happens when we use a valuable argument in ls.

command ls

As we see in the image above the ls command is used for listing in the linux terminal. With the ls command we can list in different ways like..

Commands ls

the ls command as we see it has different ways to be used but let’s look more closely at what happens when we use the ls *.c command

ls *.c

ls *.c

let’s divide the ls command to understand much better what it means.

  • ls: lists the files, folders, etc
  • *: this asterisk indicates that you will choose everything in the current address
  • .c: this indicates that we will only list files ending in .c

then as we saw the command ls *.c will list all files ending in .c

Background

Like we did before, the system also divides this process and starts by identifying the first command and checking for aliases for the specified command. What is an alias? An alias is a command in several command line interpreters (shells) that allows the substitution of a word with another string. It is mainly used to abbreviate a system command. If an alias is found, the shell checks if there are any aliases for that alias.

The next step the system takes is to do the shell expansion. An expansion is when a symbol or character is expanded in text, files, or general output. In this case the expansion to use is “*” this means that it will search for everything in the current path. When you write an expansion, before or after the “*”, all files that end or start with the string will be found. In this case, “* .c” will generate all files ending in “.c”

The shell looks for the command in the built-in functions, if it’s not there, it will fine the $ PATH, an environment variable that specifies where executable programs are located. Once found, the command is executed. Shell waits for the command to be completed, then, once it’s done, it exits the command and Bash prints the indicator again.The last step after executing the “ls * .c” command is to print the command line.

Thanks

https://blog.luigiarrieta.com

--

--