The ls command is one of the most basic and powerful tools available in the Linux command-line interface. It stands for “list” and is primarily used to display the contents of a directory. Whether you are working on a local Linux system or managing a remote server via SSH, you will have to use the ls command frequently. This command helps users quickly view files and directories, making it easier to navigate through the filesystem. It also supports a wide range of options to display additional information like permissions, ownership, file sizes, and modification dates. In this guide, we will explore the ls command in detail, starting from its basic usage to more advanced options.
Table of Contents:
What is the ls command in Linux?
The ls command in Linux stands for list and is one of the most used commands to display the contents of a directory, like files, folders, and symbolic links. The ls command helps users to:
- View the contents of the current or specified directory.
- Check file names, types, sizes, permissions, timestamps, etc.
- Understand file organization and access properties.
The default behavior of the ls command excludes hidden files and directories.
Syntax of the ls command in Linux
Below is the syntax of the ls command in Linux:
ls [Options]... [File]...
- Options are the flags that modify the behavior of the ls command.
- File is the directory (default is the current directory).
We will use example directories like intellipaat and intellipaat2 to demonstrate each command shown below:
Master DevOPS Today - Accelerate Your Future
Enroll Now and Transform Your Future
Options in the ls Command in Linux
There are the following options of the ls command in Linux:
1. Open Last Edited File Using ls -t
In Linux, the -t option in the ls command is used to list files and directories, and tells the ls command to sort the directory contents based on the modification time, with the latest modified file appearing at the top. It is useful in development when editing the files, and you want to open the last one on which you have worked.
Below is the syntax of it:
ls -t
- -t sorts the contents of the list by modification time
Example:
The above command ls -t displays the recent content modified in the current directory, i.e., intellipaat and intellipaat2, and among these two, intellipaat2 is the most recently modified.
2. Display One File Per Line Using ls -1
The ls -1 command in Linux is used to display each file or directory in a separate line, making the output clearer and easier to read. It is useful when you are working with many files or long filenames.
Below is the syntax of it:
ls -1
–1 is used to display exactly one file or directory per line in the output
Example:
The command ls -1 shows the two directories, intellipaat and intellipaat2, in one entry per line.
The ls -l command in Linux is used to display information for a specific file and directory present in the current directory, and it is also called the long listing format.
Below is the syntax of it:
ls -l
–l is used to display detailed information for a file or a directory.
Example:
The ls -l command above shows that you have two directories (intellipaat and intellipaat2), each 4KB, owned by akshat, with read/write/execute for the owner and read/execute for others, modified on July 18.
The ls -lh command in Linux is used to list the files and directories with more detailed information, like permissions, owners, and timestamps. It also displays the size of the file in a human-readable format, i.e., KB, MB, etc, instead of raw form.
Below is the syntax of it:
ls -lh
-h is used to display the information in a human-readable form.
Example:
The command ls -lh displays the information as total 8.0K, which means that the total disk space used by the listed directory entries is 8.0 kilobytes (as reported by the filesystem).
The command ls -ld is used to display the information of the directory only, without listing its contents.
Below is the syntax of it:
ls -ld [directory_name]
-ld is used to display the information of the directory only.
Example:
The above command, ls -ld intellipaat, displays the information about the directory intellipaat.
6. Order Files Based on Last Modified Time Using ls -lt
The ls -lt command in Linux is used to list the files and directories sorted by modification time, giving the most recently updated item at the top along with the information like permissions, size, date, and so on.
Below is the syntax of it:
ls -lt
- -lt option sorts the result by modification, along with the information.
Example
In the above command intellipaat2 folder is the most recently modified folder with its information.
7. Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr
The ls -ltr command in Linux is used to list the files and directories in ascending order according to the modification time, i.e., the oldest file is shown first, and the newest file will appear last.
Below is the syntax of it:
ls -ltr
- -ltr option sorts the result by modification in reverse order, along with the information.
Example:
The above command, ls -ltr, is the reverse of the -lt command and shows the oldest file first and the newest last.
8. Display Hidden Files Using ls -a(or) ls -A
In Linux, the hidden files or directories start with .(a dot), such as .gitignore, etc, but by default, these are not shown when you run the ls command. The ls -a or ls -A options help you to display these hidden files.
Below is the syntax of it:
ls -a
OR
ls -A
- -a option lists all files, including hidden ones
- -A option lists all files except . and ..
Example:
The command ls -a lists all files and directories, including hidden files (starting with a dot), and also includes the current directory and the parent directory. And the ls -A command lists all files and directories, including hidden ones, but excludes, current directory and parent directory.
9. Display Files Recursively
The command ls -R lists all the files and directories inside/etc/apt recursively from the current directory. It shows the contents of /etc/apt, then divides into further directories and so on.
Below is the syntax of it:
ls -R [directory_path]
- -R stands for recursive, i.e., it will display all files and directories inside its subdirectories.
Example:
The command ls -R lists all the files and directories, starting with the home directory and then recursively with each other.
10. Display File Inode Number Using ls -i
The ls -i command in Linux displays the inode number of each file or directory. An inode (index node) number is a data structure on a filesystem that stores metadata about a file, like file size, permissions, owner, etc.
Below is the syntax of it:
ls -i
- -i option displays the inode number of a file or directory.
Example:
In the above example, the 1551 is the inode number of the directory intellipat, and 2056 is that of intellipat2.
Get 100% Hike!
Master Most in Demand Skills Now!
11. Hide Control Characters Using ls -q
The ls -q command is used to display directory contents while hiding or non-printable or control characters (such as newline \n, tab \t, or special escape characters) in file names. It replaces these characters with a question mark (?), making the output readable and safe for terminals.
Note: Control characters are non-printable characters like newline (\n), Tab (\t), and so on.
Below is the syntax of it:
ls -q
- -q replaces control characters with ? for readability
Example:
In the above example, there are no such characters present in any file or directory, so names appear normally.
12. Display File UID and GID Using ls -n
The ls -n command in Linux displays the information about the files with their numeric UID (User ID) and GID (Group ID) instead of groups or user names.
Below is the syntax of it:
ls -n
- -n option displays UID and GID
Example:
In the above example, 1000 is the user and group ID of each directory.
13. Visual Classification of Files with Special Characters
The ls -F command in Linux adds a symbol at the end of a file or directory name to indicate its type. This makes it easier to visually distinguish between files, directories, executables, and other types. Some of the special characters appended by ls -F are as below:
Symbol |
Meaning |
/ |
Directory |
* |
Executable file |
@ |
Symbolic link |
= |
Socket |
Below is the syntax of it:
ls -F
Example:
In the above example, / indicates intellipaat is a directory, and .txt indicates that it is a regular file.
14. Visual Classification of Files with Colors
The ls –color command in Linux is used to classify files with colors.
Below is the syntax of it:
ls --color
Example:
The above example lists the directory with the auto color present in the Linux OS.
15. Customize Time Display with –time-style
The –time-style option with the ls command allows you to change your time and date information shown for files and directories. There are many formats for date and time, as shown below:
Time Style |
Command Example |
Format Displayed |
full-iso |
ls -l –time-style=full-iso |
2025-07-19 15:30:12.123456789 +0530 |
long-iso |
ls -l –time-style=long-iso |
2025-07-19 15:30 |
iso |
ls -l –time-style=iso |
07-19 15:30 |
locale |
ls -l –time-style=locale |
Jul 19 15:30 (varies by locale) |
Below is the syntax of it:
ls -l --time-style=STYLE
Example:
In the above example, the full-iso time format is used to display the time of the directories.
Display Version of the ls command
To display the version of the ls command in Linux, you can use the following command:
ls --version
Example:
In the above example, the current version of the ls command is 9.4.
Unlock Your Future in Linux
Start Your Linux Journey Today
Conclusion
From the above article, we learned that the ls command in Linux is a useful tool that allows users to list the files and directories present in the specified directories, and has a simple syntax allowing users to use it easily. It also allows you to find the files and directories as per your option by applying different filters, like ls -t, ls -a, ls -i, ls -q, and so on. You can also mark the files and directories with a specified color to make the output more readable.
If you want to learn more about the ls command in Linux, you can refer to our Linux Course, which will help you gain hands-on, real experience.
ls Command in Linux – FAQs
Q1. What does the ls command do in Linux?
It lists files and directories in the current working directory.
Q2. How do I see hidden files using ls?
Use ls -a to show all files, including hidden ones (starting with a dot).
Q3. How can I view file details with ls?
Run ls -l to see file permissions, size, owner, and modified time.
Q4. How do I sort files by time using ls?
Use ls -lt to sort files by modification time (newest first).
Q5. What is ls -lh used for?
It shows file sizes in a human-readable format (like KB, MB) with details.