The great Shell: What happens when you type “ls -l” in the shell

mohamed chedli
3 min readNov 26, 2020

--

*the output of “ls -l” to “Music” file*

What is the Shell

Simply, the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform. A shell hides the details of the underlying operating system and manages the technical details of the operating system kernel interface. There are different types of shell available. on most Linux systems a program called bash acts as the shell program. Terminal Emulators are programs that put a window and let to interact with the shell.

The prompt, $, which is called command prompt, is issued by the shell. While the prompt is displayed, you can type a command. The shell reads your input after you press Enter. It determines the command you want executed by looking at the first word of your input. A word is an unbroken set of characters. Spaces and tabs separate words. Shell script is a list of commands, which are listed in the order of execution. A task can be finished with just a few commands at a shell prompt and its printed again. Also in shell we can talk about an alias is a (usually short) name that the shell translates into another (usually longer) name or command. Aliases allow you to define new commands by substituting a string for the first token of a simple command. They are typically placed in the ~/. bashrc (bash) or ~/.But in order to reprinted again the shell will check if the command is a builtin if so we will have our prompt, which is the thing that will lead us to the path?

The Path

When you type a command into the command prompt in Linux, or in other Linux-like operating systems, all you’re doing is telling it to run a program. Even simple commands, like ls, mkdir, rm, and others are just small programs that usually live inside a directory on your computer called /usr/bin. There are other places on your system that commonly hold executable programs as well; some common ones include /usr/local/bin, /usr/local/sbin, and /usr/sbin. Which programs live where, and why, is beyond the scope of this article, but know that an executable program can live practically anywhere on your computer: it doesn’t have to be limited to one of these directories.

The shell will look inside the PATH that contain all the environment variables , specifically in the /bin folder where most of the executable files are installed .

If the corresponding path and executable file are found , the shell execute the command through the exec system call , otherwise an error message is printed the user interface .

similarly , and after the executable file was found , the shell will attribute the given stored argument “-l” to the the exe file “Ls” …

So no the full command ls -l is executed , and as a result , a full list of information about files and directories will be printed to the user interface

However, lets have a look at some system calls ..

System calls

FORK: The fork System Call. System call fork is used to create processes. The purpose of fork is to create a new process, which becomes the child process of the caller. After a new child process is created, both processes will execute the next instruction following the fork system call.

EXECVE: The execve function is most commonly used to overlay a process image that has been created by a call to the fork function. file. is the filename of the file that contains the executable image of the new process. argv.

WAIT:The wait() function will suspend execution of the calling thread until status information for one of its terminated child processes is available, or until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process.

--

--

mohamed chedli
mohamed chedli

No responses yet