Table of Contents
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:
Option | Description |
-a | List all files, including hidden files (those starting with a dot). |
-d | List directories, not their contents. |
-l | Display detailed information, including permissions, number of links, owner, group, size, and modification time. |
-F | Appends indicators to entries to denote their type (e.g., “/” for directories, “*” for executables). |
-r | Reverses the order of the Files |
-i | Display the inode number of each file |
-ltr | Sorte by modification time in reverse order. |
-t | Sort files and directories by modification time, newest first |
-n | Display group ID and owner ID |
-m | List directory contents as comma-separated |
-g | Omits owner information |
-q | Force printing non-printable characters as ‘?’ |
-Q | Displays directory contents enclosed with double quotes |
-h | Print file sizes in Human-readable format (e.g., KB, MB) |
-R | Recursively lists files and directories, including subdirectories |
-S | Sort files and directories by size |
-t | Sort files and directories by modification time |
-la | List all files and directories in long format |
-X | Sort files alphabetically by extension |
-tl | Sort 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.