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.

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.

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:

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 | | |

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store