What happens when you type ´ls -l*.c´ on your shell

What happens when you type ´ls -l*.c´ on your shell

What is a shell?

First, let us define what is a shell. By Marrian-Webster (MW) a shell is: A hard rigid usually largely calcareous covering or sup...... LOL im kidding.

Shell in computing is:

[..] is a command-line interface, which means it is soley text-based. The user can type commands to perform functions such as run programs, open and browse directories, and view processes that are currently running. Since the shell is only one layer above the operating system, you can perform operations that are not always possible using the graphical user interface (GUI). 

What is a syscall?

Pretty good. And how do we read a line from our keyboard? Let me explain to you the concept of system calls (or syscalls for short). 

A system call is a request made by a program to the operating system.
This may include hardware-related services (for example, accessing a hard disk drive), creation and execution of new processes, and communication with integral kernel services such as process scheduling. It allows an application to access functions and commands from the operating system's.
No hay texto alternativo para esta imagen

Knowing that , the Unix command to list all the files in your current directory (in a shortform to the word list [ls] (it's a great pratice to think about any command's function and why the language's inventor would name the command such)). So by typing in [ls] and hitting [ENTER]. You get :

No hay texto alternativo para esta imagen

This popular command also accepts many useful options, known as "flags", which allow you to customize its functionality by providing facilities to visualize the information requested through it.

The next parsed element is "-l", and as we have just mentioned this element is a feature or "flag" of the “ls” command, it allows us to visualize the list of elements of the directory in question in long format, thanks to this we can see more details of each contained file.

No hay texto alternativo para esta imagen

The Unix commands files and if you want to know what they do (their funcionality) using OPTIONS or FLAGS. In this case, we wantto list (output) all files and directories (writing our current directory ) with the filename extension ",c" by using the "*"[asterisk] OPTION.

As you can see in that [ls] picture up there, we have 6 files total.

FILE ONE: 0-ALIAS
FILE TWO: 1-HELLO_YOU
FILE THREE: 2-PATH
FILE FOUR: 1.C
FILE FIVE: 2.C
FILE SIX: README.md


...but only 2 of them have the filename extension ".c"

FILE FOUR: 1.C
FILE FIVE: 2.C

What we want to do is to only list [ls] these particular ".c" files. To do this, we refine the list using [ls] list command + [*] OPTION + [.c] filename extension (going to in , with another example):

ls *.c

We onlyget the files with the filename extensions ".c" (which are C programming language files).

No hay texto alternativo para esta imagen

In summary our full expression will bring us the list in long format of all files with .c extension that are present in the current directory.

No hay texto alternativo para esta imagen

What happens under the hood?

The input is broken up into words and operators.

The shell read the input firm the command line, dividing io the input ( 'ls -l *.c') into words and operators. In this process, if there are wildcards (a wildcard in Linux is a symbol or a set of symbols that stands in for other characters. It can be used to substitute for any other character or characters in a string) command, we must expand those wildcards for the actual file names we are searching. In other words, we need to search every file that ends with .c on the current directory and add them all as arguments to our command ls -l. Thus having our complete list of arguments, where ls and -l are two of them, and the rest would be the different .c files after the expansion.

Alias expansions happens

The shell identifies the first command, and checks if there are aliases(An alias is a command in various command line interpreters (shells) which enables a replacement of aword by another string. It is mainly ysed for abbreviating a system command.) for the specified command.

If an alias is found, the shell checks if there are any aliases for that alias.

Shell expansions happens

An expansion is when a symbol or character expands into larger textm files or general output. The expansion finding all files and directories is ‘*’. Writtng a string or another expansion, before or after ‘*’ will find all files that end or begin with the string. In this case, ‘*,c’ will output all files ending with '.c'

Commands executed

The shell searches for the command in the built-in functions , if it's not there, it will find the $PATH, an environmental variable specifying where the executable programs are located. Once found, the command is executed, The command in this case, ls -l will list all the .c files and their details.

Shell waits for the command to complete, then after its done, exits the command and Bash prints the prompt again.

PRINT COMMAND LINE (PS1) AND $

The environment variable PS1 is used for the format of the prompt — is the default interaction prompt for the command line: it displays the username, hostname, and full path name of the user directory. The last step after running the ‘ls -l* .c’ command is printing the command line prompt (PS1).

Thank you for reading! If this article was helpful to you, by all means, consider sharing it. Someone elsewhere could benefit from this information. Coauthoring article with an appreciatte holbi, Juan Jose Arteta,

To view or add a comment, sign in

More articles by Duvan Rodelo

  • Ethical Challenges in AR / VR

    One of the big areas of ethical concerns surrounding augmented reality and virtual reality is privacy. These devices…

  • What happens when you type holbertonschool.com in your browser and press Enter

    When you type an URL such as https://www.holbertonschool.

  • Internet Of Things

    What is the Internet of Things? The Internet of Things, or IoT, refers to the billions of physical devices around the…

  • How recursion works & .... other stuff !

    Recursion. The word alone brings back some painful and confused memory to every CS dev.

  • All stuff are Objects

    The first time when I hear about Pyhton , the message was "Python is dangerous". But in the coding way, like in the…

  • Making and Using Dynamic Libs (C)

    In order to explain the significance of using dynamic libraries, I’ll need to define some terms. First of all, a…

  • SCRUM Basics

    Whats a SCRUM ?, basically is team environtment to define objetives and personal contributions to a project…

  • Static Libraries in C

    What are C libraries? One of the tools that compilers supply C programmers. A library file contains a collection of…

  • FANTASTIC 4 TO COMPILE IN C.

    About the compiling language we have C. And you also know how to write a C program.

Insights from the community

Others also viewed

Explore topics