What happens when you type ls -l in the shell
THE SHELL :
The shell is a program that takes commands from the keyboard and gives them to the operating system to perform.
On most Linux systems a program called bash (which stands for Bourne Again SHell, an enhanced version of the original Unix shell program, sh, written by Steve Bourne) acts as the shell program. Besides bash, there are other shell programs that can be installed in a Linux system. These include: ksh, tcsh and zsh.
LS: is a command to list computer files in Unix and Unix-like operating systems.
ls is specified by POSIX and the Single UNIX Specification. When invoked without any arguments, ls lists the files in the current working directory. The command is also available in the EFI shell. In other environments, such as DOS, OS/2, and Microsoft Windows, similar functionality is provided by the
dir command. The numerical computing environments MATLAB and GNU Octave include an
ls function with similar functionality
The first time
ls appeared in the original version of AT&T UNIX, and it’s a short for the word “list”. Also it is one of the oldest commands that we still using today (almost 50 years from now).
While in its basic usage it is very simple,
ls have a long list of optional arguments we can include. So like most man pages, the
ls manual page is daunting to read (it has exactly 214 lines on Linux operating system).
ls [OPTIONS] [FILES]
ls with no option list files and directories in bare format where we won’t be able to view details like file types, size, modified date and time, permission and links etc.
The default output of the
ls command shows only the names of the files and directories, which is not very informative.
-l ( lowercase L) option causes
ls to print files in a long listing format.
When the long listing format is used, the
ls command will display the following file information:
- The file type
- The file permissions
- Number of hard links to the file
- File owner
- File group
- File size
- Date and Time
- File name
ls -l /etc/hosts
output: -rw-r — r — 1 root root 337 Oct 4 11:31 /etc/hosts
Let’s explain the most important columns of the output.
The first character shows the file type. In our example, the first character is
- which indicates a regular file. Values for other file types are as follows:
- - Regular file
The next nine characters are showing the file permissions. The first three characters are for the user, the next three are for the group, and the last three are for others. You can change the file permissions with the
chmod command. The permission character can take the following value:
r- Permission to read the file
w- Permission to write to the file
x- Permission to execute the file
In our example,
rw-r--r-- means that the user can read and write the file, and the group and others can only read the file. The number
1 after the permission characters is the number of hard links to this file.
The next two fields
root root are showing the file owner and the group, followed by the size of the file (
337), shown in bytes. Use the
-h option if you want to print sizes in a human-readable format. You can change the file owner using the
Oct 4 11:31 is the last file modification date and time.
The last column is the name of the file.