Fundamentals 9 min read

Master the Linux ls Command: 20 Essential Options Explained

This guide walks you through the Linux ls command, explaining its purpose and demonstrating twenty practical options—from basic listings and long format to sorting, hidden files, recursive traversal, and version info—so you can navigate and manage files efficiently.

Open Source Linux
Open Source Linux
Open Source Linux
Master the Linux ls Command: 20 Essential Options Explained

What is ls

The ls command lists files and directories; by default it shows the contents of the current directory. Adding options extends its functionality for detailed views, sorting, filtering, and more.

Common usages

1. Run ls without options

$ ls

2. Long listing format

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

$ ls -l

3. Human‑readable sizes

Combine -h with -l to show sizes in KB, MB, etc.

$ ls -lh

4. Sort by size

Use -S to sort files from largest to smallest.

$ ls -lhS

5. Block size unit

Specify a unit with --block-size=SIZE (e.g., --block-size=M for megabytes).

$ ls -l --block-size=M

6. Show hidden files

Files beginning with a dot are hidden; use -a to display them.

$ ls -a

7. List directories only

Use -d */ to list only directory entries.

$ ls -d */

8. Omit owner information

Use -g to hide the owner column.

$ ls -g

9. Omit group information

Use -G (or --no-group) to hide the group column.

$ ls -lG

10. Show numeric UID/GID

Use -n to display numeric user and group IDs.

$ ls -n

11. Disable color output

Use --color=never to turn off colored listings.

$ ls --color=never

12. Show inode numbers

Use -i (or -li for long format) to display each file's inode.

$ ls -li

13. Append slash to directories

Use -p to add a trailing / to directory names.

$ ls -p

14. Reverse sort order

Use -r to reverse the listing order.

$ ls -r

15. Recursive listing

Use -R to list subdirectories recursively.

$ ls -R

16. Sort by extension

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

$ ls -lX

17. Sort by modification time

Use -t to list newest files first.

$ ls -lt

18. List home directory

Use ~ as a shortcut for your home directory.

$ ls ~

19. List parent directories

Use ../ (or ../../) to view one or two levels up.

$ ls ../

20. Show version

Use --version to display the ls version.

$ ls --version

Summary

These options cover the most frequently used ls features; you can always consult the manual with man ls or ls --help for additional details.

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.

LinuxShellUnixfile-listingls command
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.