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,648FansLike
360FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

How to install CMake on Ubuntu

CMake is a cross-platform free and open-source software tool designed to build, test, and package the software. CMake uses a simple platform and compiler-independent configuration files to control the software compilation process.

How to install Lightworks on Ubuntu

Even though Linux may not get a native installer of video editing software like Adobe Premiere or Final Cut Pro, that doesn't mean there are no industry standards tools available. Lightworks is non-linear editing (NLE) video mastering app for Windows, Linux, and macOS. Installing it on Ubuntu is simple due to deb package availability.

How to install DaVinci Resolve on Fedora

Davinci Resolve is a professional application used for color correction, video editing, visual effects, and motion graphics. It is one of the extensively used software by movie industries located in Hollywood.

The 10 Best Programming Languages for Hacking

One of the significant entities we have in Cyber Security is Ethical Hacking (ETH). It is the process of detecting and finding flaws or vulnerabilities in a system that a hacker would exploit.

5 Ways to Open a Terminal in Ubuntu

Even though Ubuntu supports many applications with amazing Graphical User Interfaces (GUI), there are always reasons why users prefer using the Terminal to perform different tasks.

How to install Wine on Fedora Workstation

Linux distributions are becoming more and more popular every day, and Fedora Workstation is not left behind. This popularity brings forth the need to run Windows applications on Linux distros like Fedora. Windows has quite some excellent Software that is not available for Linux.

MUST READ

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.
Elementary OS 5.1 Hera has received a point release with a handful of new features and bug fixes, and we will be reviewing the significant changes in this article. For those new to elementary OS, this Ubuntu-based Linux distribution uses their inhouse built Pantheon desktop environment and AppCenter.

Manjaro ‘Gellivara’ XFCE Edition (17.0.5) in 10 Screenshots

Want to take a quick virtual tour Manjaro XFCE edition instead of downloading GBs worth of ISO image and then making a Live USB of it? We will make it easy for you. Here are a series of screenshots of the important aspects of Manjaro Linux in XFCE edition. This is a light-weight edition, and aims to be fast and low on system resources. You will be amazed on how it is still visually appealing and user friendly.

5 Best ways to encrypt files in Linux

Privacy is something that almost all of us have concerns about. Many people switch over to Linux because of its better privacy features. In this time, where many people believe (quite rightly so) that privacy doesn't exist anymore, Linux provides a ray of hope. Distributions like Tails OS are specifically designed for that purpose.

How to clone hard disk on Linux using Clonezilla

Disk cloning refers to the process of copying data from one disk to another, thus creating a one-to-one copy of the drive. Technically, this process is possible using the copy-and-paste method.

All about Ubuntu editions and which version should you use?

Ubuntu is one of the most popular Linux distributions developed and released by Canonical, and not without reason. It has very enriched repositories, with support for all the programs you could ever need.