Image source:

What happens when you type ls -l in the shell

First, we need to know what an environment variable is. In linux, these are simple ways to share configuration settings between multiple applications and processes. For our case with using ls, we only need the PATH variable. You can print this by greping PATH from env to see what is in it.

Greping PATH from env

These paths are separated by colon punctuation, and they contain necessary executable programs that must be available in order to have minimal functionality for booting and repairing a system. For ls, it will be in the /bin folder (short for /binaries); this folder contains bash and commonly used commands.

Showing type of ls

This command in the image above, type -a commandName shows where ls is alias’d and where it is located. An alias is simply a nickname for a command that you are able to set. In this case, ls is being color coded by the color variables within .bashrc. Now, what happens when you run a command in shell? There is an order of operations that it will check through:

When running a command, what gets checked first will be alias’s; they are located in .bashrc in the home directory. Then builtins will be checked, you can see a list of them by typing the command compgen -b. Lastly, PATH from env will be checked, this was explained above earlier.

The command type from above also displays if a command is a built-in:

How does all of this tie together? The shell uses a system call (the programmatic way a program requests a service from the kernel), process control: execute, to actually initiate your command that was processed by the shell prompt, while following the operations order of executing a command from the image above of showing type of ls.

Now lastly, here we have the breakdown of the command ls -l in the image below:

the -l flag is taking the argument char l and it tells to execute the ls command while printing it in the long format. This is what it looks like when executed:

Executing “ls -l”

By calling the alias that colors your ls prints, in the /bin directory, we print 3 empty files and 1 directory in long format.

Software Engineer living in Tokyo | Linux | Cats | | |

Software Engineer living in Tokyo | Linux | Cats | | |