The ls command is used to list all files and directories in the Linux terminal.
- Displays the contents of the current working directory or a specified path.
- Lists items in alphabetical order by default.
- The command can be customized with flags to display file permissions, ownership, size, and modification date.
- Helps users view file and directory names with optional details.
Here is example of how to list files and directories
Type the basic ls command in the terminal to display all files and directories in the current working directory.
Command:
lsOutput:

Option for the ls command
Given below are some commonly used options with the ls command to display different types of files and directories.
Syntax
ls [option] [file/directory]1. Open Last Edited File Using `ls -t `
This options lists all the files in the folder which is sorted by time which means that newest file comes first. When we use the head option in it they simply picks the first file from the list (which is your most recently changed file).
ls -t | head -1
2. Display One File Per Line Using `ls -1 `
If you want to list all files and folders in your current directory with each name on a new line, you can use the ls -1 command
ls -1
3. Display All Information About Files/Directories Using `ls -l`
The ls -l command in Linux is used to list the detailed information about the files and directories in the current folder.
ls -l 
-rw-rw-r-- 1 maverick maverick 1176 Feb 16 00:19 1.c 1st Character – File Type: First character specifies the type of the file. In the example above the hyphen (-) in the 1st character indicates that this is a normal file. Following are the possible file type options in the 1st character of the ls -l output.
File Type Indicators
- - (normal file): Represents a regular file.
- d (directory): Indicates that the file is a directory.
- s (socket file): Indicates that the file is a socket.
- l (link file): Indicates that the file is a symbolic link.
File Listing Fields Explanation
[Field 1]: File Permissions
- The next characters specify the file permissions. Every three characters represent read, write, and execute permissions for the user (owner), group, and others respectively.
- Example: -rw-rw-r-- means read-write for user, read-write for group, and read-only for others.
- Example: -rwxrwxrwx means full access for all.
[Field 2]: Number of Links
- Specifies the number of hard links associated with the file.
- Example: 1 indicates there is only one link to the file.
[Field 3]: Owner
- Shows the user who owns the file.
- Example: the owner could be a username like maverick.
[Field 4]: Group
- Indicates the group to which the file belongs.
- Example: maverick group.
[Field 5]: File Size
- Displays the size of the file in bytes.
- Example: 1176 means the file size is 1176 bytes.
[Field 6]: Last Modified Date and Time
- Shows when the file was last modified.
- Example: Feb 16 00:19 indicates the last modification time.
[Field 7]: File Name
- Displays the name of the file.
- Example: the file name could be 1.c.
4. Display File Size in Human Readable Format Using `ls -lh`
If you want see the file size, permissions, owner and date than use the below command:
ls -lh- -l: lists files in long format (with permissions, owner, size, and date)
- -h: shows the file size in a human-readable format like KB, MB, or GB instead of just raw bytes

5. Display Directory Information Using `ls -ld`
When you use “ls -l” you will get the details of directories content. But if you want the details of the directory then you can use -d option as., For example, if you use ls -l /etc will display all the files under the etc directory. But, if you want to display the information about the /etc/ directory, use -ld option as shown below.
ls -l /etc- -l means long listing format (it shows permissions, owner, size, etc.).

If you want to see the details about a directory itself (and not the files inside it), you can use:
ls -ld /etc- -d tells the system to show info about the directory itself, not what’s inside it.

6. Order Files Based on Last Modified Time Using `ls -lt`
If you want to see which files were recently changed or updated than sue the below command:
ls -ltIt lists all files and folders sorted by the last modified time

7. Order Files Based on Last Modified Time (In Reverse Order) Using `ls -ltr `
If you want to see which files were changed or updated last then use the below command:
ls -ltr - -l: shows detailed info like size, permissions, and modification time
- -t: sorts files by last modified time (newest first)
- -r: reverses the order (oldest first)
To sort the file names in the last modification time in reverse order. This will show the last edited file in the last line which will be handy when the listing goes beyond a page.

8. Display Hidden Files Using ls -a (or) ls -A
In Linux some file or folder starts with a dot (.) which means that it is hidden. These hidden files are usually used to store settings or configuration details for apps and the system.
ls -aThe above command shows all files, including the hidden ones like .bashrc, .git, or .config, along with the current . and parent .. directories.

To show the hidden files, but not the ‘.’ (current directory) and ‘..’ (parent directory).
ls -A
9. Display Files Recursively Using ls -R$ ls /etc/apt
This command lists all files and folders inside /etc/apt which includes the subfolders and their contents.
ls /etc/apt
ls -R /etc/apt To show all the files recursively. When you do this from /, it shows all the unhidden files in the whole file system recursively.

10. Display File Inode Number Using `ls -i`
Every file in Linux has a unique ID number called an inode number. This number keeps track of important details about the file like its location on disk, size, permissions, and timestamps but not its name.
To see the inode number of a file or folder use the below command:
ls -i
If you list the content of the /etc/apt directory along with their inode numbers.
ls -i /etc/apt
11. Hide Control Characters Using `ls -q`
Sometimes, files or folders may have irregular or non-printable characters which is called control characters in their names basically they can mess up your terminal display or be confusing to read.
Use ls -q command is a safe way to list files while hiding those confusing characters.
ls -q To print question marks instead of the non-graphics control characters.

12. Display File UID and GID Using `ls -n`
It shows the UID (User ID) and GID (Group ID) of the files and folders instead of just showing usernames and group names.
- This command tells you which user and group actually owns a file or folder by showing the UID (User ID) and GID (Group ID) of the files and folders instead of just showing usernames and group names.
ls -n ~/kv- Lists the output like -l, but shows the uid and gid in numeric format instead of names.

13. Visual Classification of Files with Special Characters Using `ls -F`
The ls -F command in Linux helps you quickly identify file types by adding special symbols at the end of each file name.
ls -F- / – directory.
- nothing – normal file.
- @ – link file.
- * – Executable file

14. Visual Classification of Files with Colors Using `ls -F`
Recognizing the file type by the color in which it gets displayed is another kind in classification of file. In the below output directories get displayed in blue, soft links get displayed in green, and ordinary files get displayed in default color.
ls --color=auto
15. Change the way time information is displayed using --time-style flag.
When you list files using the ls -l command in Linux, it shows the last modified time of each file. This flag lets you customize the format of the time/date shown next to each file or folder.
ls -l --time-style=long-isoThis command will display the time in YYYY-MM-DD HH:MM format. There are other options like
- locale
- full-iso
- iso
