What happens when you type `ls -l *.c` in the shell

This blog will be describing step by step of what exactly happens when we type ls -l *.c and hit Enter in a shell.

What is a shell?

Is a program in which we interact by the terminal that takes commands and gives them to the operating system to execute, basically it communicates with the computer mind.

What is a terminal?

Also called terminal emulator, provides as a way to open a window in which we can interact with the shell, where we can actually write the commands we want to execute.

What is a command?

Is an utility of the linux operating system (case sensitive) with which we give an instruction to the computer to do something we want the computer to do.

Step by step of ‘ls-l’ and ‘Enter’:

“ls” = short name of “list”

  1. Shell prints prompt ‘$’ in which after that we will write our command ‘ls-l’.
  2. The shell will read it from the getline function parsing the command line into arguments to the executing program.
  3. Will be checked if the command ‘ls’ is a built-in.
  4. The environment is copied and passed to the new process, here the shell will search in the PATH every time a command is entered.
  • A program file called ‘ls’ will be searched by the shell in the PATH, then will be find in the /bin directory where the ‘ls’ executable file will be.

What is -l?

The flag -l will include more information in the result and change the format of what is returned by organizing it as a vertical list.

What is a flag?

Flags are a way to set options and pass in arguments to the commands you run, changing their behavior based on what flags are set.

What is *.c?

The wildcard *.c will match every file ending with .c in the current directory. Knowing this, we now know that ‘ls -l *.c’ will list a vertical detailed list from the current working directory with all the files ending in .c

=> fork + wait + execve

  1. To run a command the system call fork is made to duplicate the shell parent process (creating a child process).
  2. The system call execve: Stops duplicated process, loads the new program (ls), and starts it.
  3. We use the system call wait to suspend the execution of the parent process until the child process terminates, in other words it suspends the shell prompt until the ls command finishes executing.
  4. After ‘ls-l’ is executed, the shell frees up memory, exits, and comes back to the prompt where the user can type in the input.




Holberton Student #Cohort14

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Build Calculator App UI using basic Flutter Widgets

Programming Languages to Avoid and Learn in 2022


Unity and Git

Much indexing, such wow! Nevermined now includes an integration with The Graph’s hosted service

the start.

What are APIs? and How to Secure Them?

Upgrade Ruby on Rails Project 101 — Phase 2 (Webpack)

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
Daniel Ortega Chaux

Daniel Ortega Chaux

Holberton Student #Cohort14

More from Medium

Guide to windows users switching to macOS

How To Fix 0x0 0x0 Windows Error Code? Step-by-step Guide — TheForbiz

Intel Journey

Migrate from macOS to Windows 11 for developers