Anoop Macharla
Jul 20, 2017 · 3 min read

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

The shell, what a complicated simple thing. But for any fresh of the boat engineer its just simply complicated. The shell i’m referring to is BASH (Bourne-again-shell) and as for the engineer i’m referring to is myself.

Now to best explain to you what happens under the hood is to explain what a simple ls -l command does in shell.

First.

To execute the command in shell you need to access your terminal. Terminals are emulators of shell and shell is like a window to access the back-end side of your operation system. It allows users to do everything from manipulating file to running complex programs. For every command that exist in there is a similar action or set of actions that can be done to replicate in the front end. In this post I will focus on the ls command.

File Structure — $PATH

Linux File Structure

/ : Where everything begins!

/bin : Contains programs for the system to run

/dev : Maintains list of all the devices; contains device nodes

/etc : Contains all of system wide configuration files

/home : Where a users file are stored and have the ability to write (access, add, read, delete, execute). — desktop, downloads, music, movies, applications and documents folders are stored here!

/sbin : Contains Systems binaries that preform vital tasks and write privileges are reserved for superusers.

Where are the commands stored?

Every command is stored someone and some time is a short cut for a longer action. The copy command cp job is to copy files from one folder to an another and when a user run that command it executed from the /bin/cp location.

The commands are executables that are stored in $PATH.

Similarly, the ls command (list directory content) is located in the /bin/ls directory.

What is ls ?

Graphical User Interface of Desktop
Command Line view of Desktop

ls command is to show the user what is in their directory.

The syntax for ls -OPTIONS FILEPATH . LS has a library of options such as

ls -l : List all in long format containing information about who the owner of the file is, there permissions (read/write/execute), date and time of last modification, and name.

ls -l /home/AnoopMacharla/Desktop : The FILE PATH is the relative location.

Second.

What is Shell?

Shell is a command line interface thats designed to interact with your filesystem and to execute text based programs.

3 types of Shell:

  1. SH: Original Bourne Shell
  2. BASH: Bourne-again Shell
  3. CSH: C-Shell
  4. ZSH: Zhong Shao
  5. KSH: Korn Shell

What It can do?

  • execute text based programs
  • manipulate files: copy, paste, move, remove, append, read, search, and execute.
  • access control
  • scripting: do all the above non interactively and by using variables and loops.

Who created it?

Thompson Shell: written by Ken Thompson at Bell labs who made the first unix shell and was written by Ken Thompson at Bell Labs.

Upward compatible version of Thompson Shell is called PWD shell or Mashey shell “sh” which introduced shell programing, error handling, PATH, shell scripts. Then after ‘sh’ was created by Stephan Bourne and rewritten. Which is now the standard shell in most unix and linux systems.

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade