13 ways to use the ls command to list files on Linux

LS command lists files and directories in Linux and Unix systems. Is it just that? Let's dig into details and find out what other ways you can use the command effectively in today's session of Terminal Tuts.

The LS command is one of the first commands that any Linux newbie will learn after installing their first Linux operating system. Not only does it come in handy with Linux Desktop systems, but it’s also an excellent utility for server management.

LS command lists files and directories in Linux and Unix systems. Other than listing the files and directories, you can use this command to get more information about a file or directory. This data includes who owns the file, size of the data, permissions given to the file, and even the time of the creation of the file.

ls command uses in Linux with examples

The basic syntax of the LS command is as follows:

ls [option] [path_to_file/directory]

It is not a surprise that we use the LS command daily, but have we exhausted all the options that come with this great utility? In this article, we will look at 13 LS commands that may be of help in your everyday interaction with Linux systems.

1. List files and directory without additional options

ls

It is one of the basic LS commands that every Linux user executes daily. It only lists files in a directory without any further information like permissions and file owner. Take a look at the image below.

LS command Image
LS command Image

From the above image, we ran the LS command on the Desktop, and it listed all the files present.

2. List files and Directories using the LS -L

ls -l

The LS -L command lists files and directories together with additional information like permissions, owner, date of creation, etc. Let’s look at the image below before getting to every column and data presented.

LS -L Command Image
LS -L Command Image

From the above image, we see the information listed under seven columns. We will look at every single column and what it represents.

  • Column One: It shows the file type and the user permissions assigned to the file.
  • Column two: Indicates the number of blocks of memory taken by the file.
  • Column three: It represents the owner or user who created the file.
  • Column four: In Linux systems, users are associated with different groups. This column represents the group to which the owner belongs.
  • Column five: It represents the size of the directory or file. It is calculated in bytes.
  • Column six: This is the column that deals with time stamps on the file—the date of creation and modifications.
  • Column seven: It represents the original name of the file or directory as given by the user.

3. List files with LS -A

ls -a

In every operating system, we have hidden files and folders that are not displayed even with the LS -L command. Unless you have enabled the “show hidden files feature.” In Linux systems, hidden files are those that start with a dot(.) letter. The LS -A command lists all data, including hidden files (dot-files).

LS -A Command Image
LS -A Command Image

From the above image, we first ran the LS command, which listed only a few files. When we ran the LS -A command, on the same directory, it listed all files, including the hidden files.

4. List files with the LS -LH

ls -lh

The LS -LH command is commonly known to list files in a human-readable format. It is mainly useful when it comes to the size of the data. Unlike the LS -L command alone, which lists the size of files in bytes only, the LS -LH command will show the exact size in bytes(b), kilobytes(kb), megabytes(MB), etc. See the image below.

LS -LH Command Image
LS -LH Command Image

From the image above, the LS -L command file size in bytes, which is not so human-friendly. The LS -LH command output the files with the file sizes in a straightforward format.

5. List files with the LS -F

ls -F

Suppose you want to know directories in an output of an LS command, then we will use the LS -F, which adds a forward slash at the end of every directory name. See the image below.

LS -F Command Image
LS -F Command Image

Note, unlike other previous commands, the F option is in capital letters.

6. Use LS -R to list files in reverse order

ls -r

If you wish to list files in reverse order with the last file in the directory listed first, use the LS -R command. See the image below.

LS -R Command Image
LS -R Command Image

From the above image, we first executed the LS command, and the first file was 1wolf14.zip, while the last was prince-of-persia.zip. With LS -R command, the files were reversed. prince-of-persia.zip became the first while 1wolf14.zip was at the last index.

7. List files and directory contents recursively with LS -R

ls -R

Suppose you want to list files together with the contents of directories present in the path, then we will use the recursive (R) feature that comes with Linux systems. We will use the LS -R command.

LS -R (recursive) Command Image
LS -R (recursive) Command Image

From the image above, we first executed the LS command, which listed the files and directories present. In the second command, we ran LS -R command, which not only listed files and directories present, but also contents inside those directories.

8. Show the latest modified file with LS -LTR

ls -ltr

You can use LS -LTR command to show the latest modified files or directories in order. The latest modified is listed as the last while the oldest outputted as the first. Take a look at the image below.

LS -LTR Command image
LS -LTR Command image

From the image, we see the oldest modified file is the ‘DSC_0627.JPG’ edited on March 13th, while the newest is ‘youtubeDownloader’ modified on April 10th.

9. List files and directories by size using LS -LAS

ls -laS

You can also sort your files by size using the ls -las command. The most extensive file will be displayed first while the smallest last. See the image below.

LS -laS command Image
LS -laS command Image

10. List the inode number of files and directories using LS -I

ls -i

Inode numbers, also referred to index numbers, are unique identifiers assigned to every file and directory upon creation. To list files and directories together with their inode numbers, use the LS -I command. See the image below.

LS -I command image
LS -I command image

11. List UID and GID values with the LS -N

ls -n

To list files and directories together with their User Identifier(UID) and Group Identifier(GID) values, use the LS -N command. See the image below.

LS -N command linux
LS -N command Linux

In the above image, column three and four represent the UID and GID values, respectively.

12. List information of a directory using the LS -LD

ls -ld

When we run the LS -L command on a directory, it will output all the contents and information about the file. If you wish to list only the information about the directory/folder, then we will use the LS -LD command. See the image below.

LS -LD Command image
LS -LD Command image

From the above image, we first executed the LS command on the lib folder. It outputted the contents of the lib directory. The second command, we ran the LS -LD command that returned information about the lib directory.

13. List all usages of LS command using LS -HELP, and MAN

ls --help
man help

Assuming you are a Linux newbie who wants to learn about the LS command or a user who wants to exhaust all the options that come with the LS command, there are two ways you can achieve that. Use the LS –HELP command.

LS --Help Command
LS –Help Command

Else, use the MAN LS command.

MAN LS command image
MAN LS command image

Conclusion

Those are some of the LS commands you can use in your everyday activity with Linux systems. The command-line way of listing files is quite useful for managing servers without a graphical user interface or in combination with other commands like grep to filter results. Do you have a command that you want to share with our readers? Feel free to post in the comment section below. If you find this article useful, feel free to share the link with friends.

Arun Kumar
Arun did his bachelor in computer engineering and loves enjoying his spare time writing for FOSS Linux. He uses Fedora as the daily driver and loves tinkering with interesting distros on VirtualBox. He works during the day and reads anything tech at night. Apart from blogging, he loves swimming and playing tennis.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,437FansLike
374FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

How to change Hostname on Ubuntu

Generally, a hostname is just an assigned name to a computer, laptop, or any other connected device to a network. You can say a hostname is a computer's nickname, and it is used to identify the machine over the network uniquely.

Manjaro vs. Ubuntu – which is better for you?

If you are a person associated with Computer technology and spend most of the time in the open-source arena, you must have heard or worked with some of the popular Linux distributions we have in the market. Some of the names that you will never miss are; Ubuntu, Arch Linux, Debian, and Mint.

9 Useful Tips Working with Operating System using Python

There are several situations when we want to work with the operating system using python. We may want to see the user details or want to do some tasks with the files and directories. If you are a system administrator, you will find it useful to work with Operating System as one can easily automate some repeating tasks of the Operating System using python.

System76 Lemur Pro Review

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.

Top 10 New Features in Linux Kernel 5.8

Linus Torvalds recently announced the release of Linux Kernel 5.8, and he seems delighted with it. He has pointed it out as the most significant release of all time. To developers, this new kernel comes with an addition of 800,000 new code lines and more than 14,000 changed files. To the average user, you might not see many eye-candy changes, as seen in the earlier releases.

How to install Flutter on Linux

Do you want to install Flutter and start creating awesome Android and iOS applications? Then you have come to the right place. Here is a comprehensive tutorial on how to install Flutter on Linux. If you are new to Flutter, don't worry, we got that covered too as we shall go in-depth understanding of Flutter and what it brings to the table.

MUST READ

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

Beaker Browser: A P2P web browser you must try

I think we can all agree on the fact that the web browser is an integral part of our Linux systems, or any computer system, for that matter. We have had several fulfilling options for browsing the web, like Firefox, Brave, Vivaldi, Tor, etc. and they have worked pretty well, but also pretty much in the same way, except for Tor, which is much better for anonymity.

5 Best Notepad++ Alternatives for Linux

Notepad++ has been the de facto standard for source code editors for nearly 16 years, almost since its creation in 2003.  For Windows users, that is.  For years, Linux users had no source code editor that compared to Notepad++ with all its bells and whistles, such as code folding, scripting, markup languages, syntax highlighting, auto-completion for programming (limited).

5 Things to do when your Linux system GUI freezes

All operating systems freeze at some point and, Linux distributions are no exceptions. In this post, we are going to look at five methods you can apply to your frozen system before thinking of plugging out the power cable or holding down the power button to power off the PC.

6 Best Linux Distributions for Beginners

Making the shift to Linux is not as complicated as some people make it out to be. There is a variety of Linux distributions available that cater to the needs of people who are planning on making the jump to Linux from any other operating system.