What is the ls command in Linux & How to use it?

In this article, you will learn, what is the ls command in Linux & how to use it?

The ls is the command in Linux and Unix-like operating systems. The use of the ls command is to list the content of the current directory by default and also we can use it to list the content of other directories after specifying the path of that directories. So, I will discuss the most important arguments along with the ls command.

If you like to watch the ls command video then you can watch the video.

ls command in Linux | Watch ls command in the video.

How to get help for the ls command

I always suggest reading the manual page and help. So, it will give you an in-depth introduction to the command.

So to get the manual page, type the below command,

man ls

But, to get the only command options, you can type the below command.

ls --help

Syntax of the ls command

Now you know how to get help for the ls command. So, let’s talk about ls syntax. The syntax of the ls command is as below,

Syntax: ls [option] File….

So let’s start using of ls command in Linux.

Listing content of the current directory using ls command

If you want to check the content of a directory, then you can use ls command without any argument. So, only type as below.

ls
ls command in linux
The output of the ls command.

Long listing using ls command

You can use the ls command to long-list. To long-list, you have to use -l argument.

ls -l

As a result, you can see in the below picture.

ls -l command in linux
The output of the ls -l command

Listing the content in a human-readable format

Usually, When you use the ls -l command, then the file information is shown in bytes which is not easy to get the file size information so, if you want to get the size in human-readable format, use -h argument along with -l.

ls -lh

Also, you can find a detailed structure with examples in the below picture.

ls -lh command in linux
The output of the ls -lh command.

Listing files in last modified using ls -lt command

So, If you want to list the directory content in sort of last modified time, then you have to use -t argument.

ls -lt
ls -lt command
The output of the ls -lt command.

Listing hidden files using ls -la command

You can use the ls command along with -a argument to list the hidden files. For your information, all the hidden files in Linux start with . (dot). So the command will look like the below.

ls -la
ls -la command
The output of the ls -la command

Listing the inode value of the files

You can use the ls command along with -i argument to list the inode values. So you can use the below command to get the inode values.

ls -li

Also, you can see the use of this argument in the below picture.

ls -li
The output of the ls -li command.

Conclusion

In this article, you learned about the ls command and you can see that it is easy to use and you get a lot of information. So, I hope you understand, but if you have any questions, you can ask in the comment section.

You may like to read about the below topics.

One comment

Leave a Reply

Your email address will not be published.

  1. Hey would you mind stating which blog platform you’re using?
    I’m looking to start my own blog in the near future but
    I’m having a hard time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design and style seems different
    then most blogs and I’m looking for something completely
    unique. P.S Sorry for getting off-topic but I had to ask!