The ls command in Linux

Windows Articles

How to install Brackets in Windows 10 plus extensions

Hello! Brackets is an open-source code editor designed by Adobe for web developers. Additionally, it has a very simple and modern interface...

How to install Docker on OpenSUSE 15.2 / 15.1?

Docker is a fairly popular technology in today’s sysadmin. It is logical to think because it means a complete change in the...

How to analyze the network with IP Tools for Android

Hi! If you want to analyze and adjust the network almost professionally, then this post is for you. Indeed, IP Tools is...

How to install GNU Fortran on Ubuntu 20.04 / 18.04?

Not everything old is bad. This is how it is. Well, while it is true that there are many programming languages today, there are...

How to install Unity Desktop on Ubuntu 20.04?

Unity Desktop was for a long time the default desktop environment in Ubuntu. Thanks to this, Ubuntu gained a great personality and...
Mel Khamlichi
Mel Khamlichihttp://www.osradar.com
Founder of Osradar, from Amsterdam Netherlands

Many people who have used Windows or Mac OS all their lives don’t know how powerful and simple the terminal of a GNU/LINUX distribution is to use because in these operating systems the use of the terminal is reduced and if you are a user who uses the pc for internet browsing then it is likely that you have never used an interpreter commands in the terminal.

Nowadays, most GNU/LINUX distributions have evolved to such an extent that it is possible that a user with little knowledge of general computing can develop without having to use a terminal.

System administrators are usually very skilled at using the terminal since the execution of their commands allows us to perform commands to the system and with it we can do practically anything in an amazing time and efficiency; from opening a file, such as copying it, moving it or even showing all the contents of files in a folder; but if you are not a system administrator or have simply never used the terminal in any GNU/LINUX distribution, do not worry today in this article we will explain the use of a simple but very useful command: the ls command.

ls command basic usage

The ls command is one of the most important and basic commands in the world of unix systems, it serves to display files within a directory. The screen output will be shown in the terminal and according to the options used you can modify the way it is shown.

The most basic way to use the ls command is to simply invoke it in the terminal itself:

             ls

And then it will list all the files and folders that are inside the home folder. To display another folder, simply leave a space and place the path to the folder to be displayed. For example, I will show the entire contents of the Dir.

          ls /home/angelo/Dir

Using ls

That is the most basic way to use the command but we can also invoke the command along with the –help option to show all the help available on it.

ls help
ls help

Of course, we see the image with the help available for the command and we may feel overwhelmed by the amount of information provided, but basically what is shown are the options that are added to the command to extend its functionality. Some of the most important options are:

 

Options

Description

-a

Do not ignore entries starting with .

-A

Do not list implied . And ..

-d

List directories themselves, not their contents

-i

print the index number of each file

-l

Use a long listing format. Displays information such as permissions and owner of the folder or file.

-r

reverse order while sorting

-R

List subdirectories recursively. Displays the contents of the directory subfolders.

-s

print the allocated size of each file, in blocks

-S

sort by file size, largest first

-t

sort by modification time, newest first

-U

do not sort; list entries in directory order

-X

sort alphabetically by entry extension

 

Some examples of using the ls command with its options

As stated at the beginning of this article, the ls command is one of the simplest commands to learn and we just have to add the needed option to the command.

Example 1:

List all files and folders, including hidden files.

         ls -a PATH

In this case:

         ls -a /

To display all files in the root directory

ls -a

Example 2:

Show complete information about files and folders with option –l

           ls -l /home/angelo/

ls with option -l

Example 3:

Show files and folders in a reverse order

To do this we use the option -r

           ls -r /home/angelo/

ls with option-r

Show only the directories

In this case we will use the option -d and the asterisk before the symbol /

           ls -d */

ls with option -d

Using the previous command it shows us only the directories or folders from where the prompt is located

Example 5:

Sort by file size

With the option -S we can sort the directories by size.

         ls -S /home/angelo/

ls with option -S

 

Conclusion

As a conclusion we can say that, far from being complex and reserved for extraordinary people and some computer skills, the terminal tool is a powerful tool that through its commands we can simply execute commands to the operating system with much greater speed and efficiency.

The ls command used to list the files is one of the most essential and simple commands to learn; its different options allow, among other things, ordering and defining the way in which it lists the files.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to install Brackets in Windows 10 plus extensions

Hello! Brackets is an open-source code editor designed by Adobe for web developers. Additionally, it has a very simple and modern interface...

How to install Docker on OpenSUSE 15.2 / 15.1?

Docker is a fairly popular technology in today’s sysadmin. It is logical to think because it means a complete change in the...

How to analyze the network with IP Tools for Android

Hi! If you want to analyze and adjust the network almost professionally, then this post is for you. Indeed, IP Tools is...

How to install GNU Fortran on Ubuntu 20.04 / 18.04?

Not everything old is bad. This is how it is. Well, while it is true that there are many programming languages today, there are...

How to install Unity Desktop on Ubuntu 20.04?

Unity Desktop was for a long time the default desktop environment in Ubuntu. Thanks to this, Ubuntu gained a great personality and...