Fundamentals 9 min read

Mastering the ls Command: 20 Essential Options for Linux File Listing

This guide explains the Linux ls command, its purpose, and walks through twenty practical options—including long format, human‑readable sizes, sorting, hidden files, recursive listing, and version display—so readers can list and interpret directory contents efficiently.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering the ls Command: 20 Essential Options for Linux File Listing

The ls command is a core Linux utility used to list files and directories; by default it shows the contents of the current directory. Mastering its many options lets users obtain detailed, sortable, and formatted views of the filesystem.

What is ls?

ls

lists directory entries. Without arguments it simply prints names, but with flags it can display permissions, owners, sizes, timestamps, and more.

Commonly Used Options

1. No parameters

Running ls without flags lists only names.

ls

2. Long listing format

Use -l to show a detailed list with permissions, links, owner, group, size, modification time, and name.

ls -l

The columns represent:

File type and permissions (e.g., d for directory, - for file, l for symlink).

Number of hard links.

Owner name.

Group name.

Size in bytes (directories are typically 4096 B).

Last modification timestamp.

File or directory name.

3. Human‑readable sizes

Combine -h with -l to display sizes in KiB, MiB, etc.

ls -lh

The -si flag works similarly but uses decimal units (1000 B). Example:

ls -si

4. Sort by size

Use -S (often together with -lh) to sort entries from largest to smallest.

ls -lhS

5. Specify block size

Change the displayed unit with --block-size=SIZE (e.g., M for megabytes).

ls -l --block-size=M

6. Show hidden files

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

ls -a

7. List directories only

Use -d */ to display only directory entries.

ls -d */

8. Omit owner information

Flag -g hides the owner column.

ls -g

9. Omit group information

Use -G (or --group-directories-first in some shells) to hide the group column.

ls -lG

10. Show numeric UID/GID

Flag -n prints owners and groups as numeric IDs.

ls -n

11. Disable color output

Many distributions enable colored output; --color=never turns it off.

ls --color=never

12. Print inode numbers

Use -i to show each file's index (inode) in the first column.

ls -li

13. Append '/' to directories

Flag -p adds a trailing slash to directory names.

ls -p

14. Reverse sort order

Use -r to invert the default sorting order.

ls -r

15. Recursive listing

Flag -R lists sub‑directories recursively.

ls -R

16. Sort by extension

Use -X or --sort=extension to order files by their suffix.

ls -lX

17. Sort by modification time

Flag -t lists newest files first.

ls -lt

18. List home directory

Use ~ as a shortcut for the current user's home.

ls ~

19. List parent directory

Use ../ (or ../../ for two levels up) to view the directory above.

ls ../
ls ../../

20. Show version

Flag --version prints the ls program version.

ls --version

Conclusion

These options cover the most useful ways to tailor ls output for everyday tasks. For additional details, consult the manual pages with man ls or 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.

linuxUnixfile-listingls command
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.