ls -l in the shell

¿What happens when you type ls -l in the shell?

Previously I’ve already talk about the command <ls> here. So before start reading this article I recommend you to check that other first.

Now let’s get started. First we need to define:

¿What is a shell?

  • Is a command interpreter in operating system such as Unix or Linux
  • It is a program that executes other programs
  • It provides an interface to the system so the user can run different commands or utilities/tools with some input data.

In fact there are several kinds of shell’s, such as Bourne shell, Bash, Zsh, etc… and you can choose the one that fixes you the most.

¿What does the shell do?

  • Wait for the user to type a command
  • Parse the command and saved into a string, then split that string by every argument (called tokens).
  • Then check if those are aliases, built-ins or executables (binaries). In this case the command ls is located in the directory into the (which is an enviromment variable and looks like this: /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin::/usr/games:/usr/local/games ) As you can see in the PATH are different absolute paths separated by colons; therefore ls will just look for the /bin directory
  • Executes the matched command or print an error if the input typed is not valid

Now that we have an overview of what shell does, let’s move onto our other question, what happens with ls -l

ls. Listing Files

The command ls is used in Linux to list files, but now we are adding a flag -l… What this flag do is that shows us a long list, with details of the files in the current directory:

As you can see the command displays the files in the current directory, and it shows details of every file. And here is what do that information means:

¡Now you know what happens behind scenes when you type a command. so keep reading and practicing more!

--

--

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