Fundamentals 8 min read

Mastering the Linux ls Command: 20 Essential Options Explained

This guide walks you through the 20 most useful ls command options, showing how to list files, display detailed information, sort by size or time, show hidden items, format output, and more, with clear examples and screenshots for each feature.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering the Linux ls Command: 20 Essential Options Explained

The ls command is a fundamental tool for navigating and inspecting files and directories in Linux. Below are twenty practical options that extend its default behavior, each illustrated with example commands and screenshots.

1. List without parameters

Running ls without any flags simply lists the names of files and directories in the current directory.

ls

2. Long listing format

Use the -l flag to display a detailed list, showing permissions, link count, owner, group, size, modification date, and name.

ls -l

3. Human‑readable sizes

Combine -h with -l to show file sizes in a readable format (e.g., 6.5M instead of bytes).

ls -lh

4. Sort by size

The -S flag sorts entries by size, largest first.

ls -lhS

5. Specify block size

Use --block-size=SIZE to force a particular unit (K, M, G, etc.). Example:

ls -l --block-size=M

6. Show hidden files

Files beginning with a dot are hidden; the -a option reveals them.

ls -a

7. List only directories

The -d flag prevents descending into directories, showing only the directory entries themselves.

ls -d */

8. Omit owner information

Use -g to hide the owner column while keeping group information.

ls -g

9. Omit group information

Combine -l with -G (or use -lG) to hide the group column.

ls -lG

10. Show numeric UID/GID

The -n option displays owners and groups as numeric IDs.

ls -n

11. Disable color output

Some distributions colorize output; --color=never disables it.

ls --color=never

12. Print inode numbers

Use -i to prepend each entry with its inode number.

ls -li

13. Append slash to directories

The -p flag adds a trailing / to directory names.

ls -p

14. Reverse sort order

Apply -r to reverse the default sorting order.

ls -r

15. Recursive listing

With -R, ls lists subdirectories recursively.

ls -R

16. Sort by extension

Use -X or --sort=extension to order files by their file‑type extension.

ls -lX
ls --sort=extension

17. Sort by modification time

The -t flag sorts entries so the most recently modified files appear first.

ls -lt

18. List home directory

Use the tilde ~ shortcut to refer to the current user's home directory.

ls ~

19. List parent directory

Navigate upward with ... For example, ls ../ lists the immediate parent, while ls ../../ lists two levels up.

ls ../
ls ../../

20. Show ls version

Display the version of the ls utility with --version. ls --version For any of these options, you can always consult the manual page with man ls or view a quick help summary using ls --help.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxShellcommand-lineTutorialfile managementls
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.