Andrés Felipe García Rendón
4 min readDec 1, 2019

--

What happens when you type ls -l in the shell

The Shell

The Linux command interpreter or shell is the program users interact with in a terminal emulation window. The terminal emulation window can be one in the workstation’s Graphical User Interface mate-terminal on Linux. Alternatively, it can be an application such as SSH secure shell client or PuTTY on a Windows PC that's logged into Linux over the network.

The shell used in the School of Computer Science & Informatics is bash Bourne Again Shell. There are other shells available such as the Bourne Shell, the C-Shell and the TC-Shell, and you can choose to use a different shell if you prefer. They all have similar characteristics but each has its own particular features. This document assumes you are using bash.

Command ls

The command ls is use for lst the contents of the directories (by default order the output alphabetically).

Its syntax is of the form: [options] [file …]

Some of your options are:

-to all files, even those that begin with period (.).
-A List all files in directories, except those that begin with a period. (.) and those that begin with a double point (..).
-F indicates type: / directory, * executable, @ symbolic link.
-h will indicate the size in KB, MB, etc.
-l listing in long (or detailed) format.
-S classifies the contents of the directories by size, with the largest files first.
-r reverses the order of departure.
-R recursively lists the subdirectories found.
-t sort by date of last modification.
-u sort by date of last access.
-x presents the files by columns.
-i precedes the output with the i-node number (see command ln).

In an output of type ls -l

# ls -l
total 12
-rw-r — r — 1 root root 100 Apr 6 21:19 file.txt
drwxr-xr-x 3 root root 4096 Apr 7 01:44 folder2
drwxr-xr-x 2 root root 4096 Apr 6 22:19 folder3

The first character of each line indicates the type of file and can be:

- indicates regular file.
d indicates directory.
l symbolic link (see command ln).
c character devices.
b block devices.
s connections with the local domain.
p connections.

The following of 3 characters, indicate the permissions of: owner u, group g and others or.
If the owner’s x is replaced by one, that s indicates that the setuid bit (4000) is activated.
If the group’s x is replaced by an s they indicate that the setgid bit (2000) is activated.
If the owner’s x is replaced by a T, they indicate that the stick bit (1000) is activated.
If the execution bits have not been activated, the letters S or T appear in uppercase
The second field indicates the physical file link counter.
The third and fourth fields indicate the owner and the owner group of the file respectively.
The fifth field indicates the size of the file in kbs.
The sixth field indicates the date and time of the last modification of the file.

Examples of exits:

ls without parameters.

# ls
file.txt folder2 folder3

ls with the -l parameter

# ls -l
total 12
-rw-r — r — 1 root root 100 Apr 6 21:19 file.txt
drwxr-xr-x 3 root root 4096 Apr 7 01:44 folder2
drwxr-xr-x 2 root root 4096 Apr 6 22:19 folder3

PATH

The PATH (the path, the path) is an environment variable. The environment variables contain information that is accessed through the name of the variable (as in programming languages).

In PATH, all system directories are found, where system functions are stored. When we execute ls -l, the system uses the global PATH variable, searches each of its directories and when it finds the similarity with the data entered, it executes the function.

In this case the ls command is in the / bin / directory, the system searches each directory of the PATH variable and when it reaches the / bin / directory, executes the ls command.

## ~/bin/ to be searched before all other directories ## PATH=$HOME/bin/:$PATH

--

--

Andrés Felipe García Rendón

Web Developer graduated from Holberton School. With experience in as C, Python, NodeJS, React, React Native, HTML, CSS, Boostrap and Flexbox