Fundamentals 8 min read

Master the Linux ‘ls’ Command: 20 Essential Options Explained

This guide introduces the Linux ls command, explains its default behavior, and provides detailed examples of twenty useful options—including long listings, human‑readable sizes, sorting, recursive listing, and more—so readers can efficiently list and inspect files and directories.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master the Linux ‘ls’ Command: 20 Essential Options Explained

ls command overview

The ls utility lists files and directories. By default it displays the contents of the current directory, and a wide range of options allow you to customise the output for various tasks.

Basic usage

ls

Long listing format

ls -l

The long format shows several columns:

File type and permission bits

Number of hard links

Owner name

Group name

Size in bytes (directories are typically 4096 B)

Modification timestamp

File or directory name

Human‑readable sizes

ls -lh

The -h flag prints sizes using KiB, MiB, etc., making them easier to read.

Sort by size

ls -lhS

The -S option sorts entries from largest to smallest.

Specify block size

ls -l --block-size=M

Use --block-size=SIZE (e.g., M for megabytes) to change the unit used for the size column.

Show hidden files

ls -a

Files whose names start with a dot ( .) are hidden; -a reveals them.

List only directories

ls -d */

The -d flag prevents descending into directories and lists the directory entries themselves.

Omit owner information

ls -g

The -g option hides the owner column.

Omit group information

ls -lG

The capital G flag suppresses the group column.

Numeric UID/GID

ls -n

Print numeric user and group IDs instead of names.

Disable colour output

ls --color=never

Some distributions colourise the output; this option turns colour off.

Print inode numbers

ls -li

The -i flag displays each file’s inode number in the first column.

Append ‘/’ to directories

ls -p

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

Reverse sort order

ls -r

Reverse the default sorting direction.

Recursive listing

ls -R

List sub‑directories recursively.

Sort by extension

ls -lX
ls --sort=extension

The -X or --sort=extension options order files by their suffix.

Sort by modification time

ls -lt

The -t flag sorts entries with the newest files first.

List the home directory

ls ~

The tilde ( ~) expands to the current user’s home directory.

List parent directories

ls ../
ls ../../

Use .. to refer to the parent directory; multiple components move up further levels.

Show version information

ls --version

Displays the version of the ls program.

For a complete reference, 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.

command-lineUnixfile 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.