Linux

ls Command with Examples: Helpful Guide for Beginners

Introduction

Linux is a free, open-source system similar to Unix and based on the Linux kernel. It was created by a person named Linus Torvalds in 1991. One of its most prominent features is distribution, which allows organizations and groups to create modified versions of the Linux system called distributions. Among the most popular distributions, we find Ubuntu, Fedora, Debian, and CentOS.

Linux allows multiple users to perform multiple tasks at the same time. It can be called a multi-user and multitasking system.

The Command Line Interface (CLI) is one of the indispensable tools in the Linux system and is not limited to it only. We find it in other systems such as Windows and macOS. CLI is a text-based interface through which you can write commands that interact with a computer’s operating system. command syntax controls the way you interact with the system.

In the Linux system, many commands help in controlling and executing tasks, and one of the most important of these commands is the ls command. Which we will learn about through this article. Below, what is the ls command and its syntax, and we will also learn about ls command options and how to use them.

What is ls Command?

ls command is one of many Linux commands used within the Command Line Interface (CLI). Its purpose is to list files and directories in the current directory. This command provides valuable information about files, directories, and their attributes. Write this command without any option to list files and directories in alphabetical order.

ls Command Syntax

The ls command follows this syntax in Linux

ls [option] [file] or [directory]

ls command Options

Below is a table of options for this command, along with their description:

OptionDescription
-aList all files, including hidden files (those starting with a dot).
-dList directories, not their contents.
-lDisplay detailed information, including permissions, number of links, owner, group, size, and modification time.
-FAppends indicators to entries to denote their type (e.g., “/” for directories, “*” for executables).
-rReverses the order of the Files
-iDisplay the inode number of each file
-ltrSorte by modification time in reverse order.
-tSort files and directories by modification time, newest first
-nDisplay group ID and owner ID
-mList directory contents as comma-separated
-gOmits owner information
-qForce printing non-printable characters as ‘?’
-QDisplays directory contents enclosed with double quotes
-hPrint file sizes in Human-readable format (e.g., KB, MB)
-RRecursively lists files and directories, including subdirectories
-SSort files and directories by size
-tSort files and directories by modification time
-laList all files and directories in long format
-XSort files alphabetically by extension
-tlSort files by modification time

You can combine these options to achieve your goal when browsing Linux.

Practical Examples of The ls Command

Here are some practical examples of the uses of ls command:

How to List Files in a Directory:

ls

Display Detailed Information:

ls -l

List All Linux Files:

ls -la

List One File Per Line:

ls -1

Show Hidden Files:

ls -a

Sort by Size in Human-Readable Format:

ls -hS

Explore Subdirectories Recursively:

ls -R

Conclusion

ls command is very important for Linux users, as it cannot be dispensed with because of its effective role in browsing directories. Therefore, users must master this command. In this article, we mentioned all the options and also some practical examples of how to use them. If you have any questions or suggestions, you can use the comments box below. If you find this article useful, we advise you to save it in your favorites.

We use cookies and other tracking technologies to improve your browsing experience on our site, show personalized content and targeted ads, analyze site traffic, and understand where our audiences come from. By choosing Accept, you consent to our use of cookies and other tracking technologies.