Fundamentals 10 min read

Mastering the ls Command: 20 Essential Options You Need to Know

This guide walks through the Linux ls command, explaining its basic behavior and demonstrating 20 useful options—including long listing, human‑readable sizes, sorting, hidden files, recursive listing, and version display—so readers can list files and directories more effectively.

Linux Tech Enthusiast
Linux Tech Enthusiast
Linux Tech Enthusiast
Mastering the ls Command: 20 Essential Options You Need to Know

ls command overview

The ls utility lists files and directories in the current working directory. By default it prints only the names; adding options changes the format, sorting, and displayed metadata.

1. Run without arguments

Simply typing ls lists the entries in the current directory.

ls
ls output
ls output

2. Long listing format

Use -l to display a detailed list that includes permissions, link count, owner, group, size, modification time, and name.

ls -l
ls -l output
ls -l output

The columns are interpreted as follows:

Column 1 – file type (d for directory, – for regular file, l for symlink) and permission bits.

Column 2 – number of hard links.

Column 3 – owner name.

Column 4 – group name.

Column 5 – size in bytes (directories usually report 4096 bytes).

Column 6 – last modification timestamp.

Column 7 – file or directory name.

3. Human‑readable sizes

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

ls -lh
ls -lh output
ls -lh output

The --si option works like -h but uses powers of 1000 instead of 1024.

ls -si
ls -si output
ls -si output

4. Sort by file size

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

ls -lhS
ls sorted by size
ls sorted by size

5. Custom block size

Specify --block-size=SIZE to display sizes in a chosen unit (e.g., M for megabytes).

ls -l --block-size=M
ls with block size
ls with block size

6. Show hidden files

Files whose names start with a dot are hidden; -a lists them.

ls -a
ls -a output
ls -a output

7. List only directories

Use -d */ to display directory entries without recursing into them.

ls -d */
ls -d output
ls -d output

8. Omit owner information

Use -g to hide the owner column.

ls -g
ls -g output
ls -g output

9. Omit group information

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

ls -lG
ls -lG output
ls -lG output

10. Numeric UID/GID

Use -n to display numeric user and group IDs.

ls -n
ls -n output
ls -n output

11. Disable colorized output

Some distributions enable color; --color=never turns it off.

ls --color=never
ls without color
ls without color

12. Show inode numbers

Use -i to prepend the inode number to each entry.

ls -li
ls -li output
ls -li output

13. Append '/' to directories

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

ls -p
ls -p output
ls -p output

14. Reverse sort order

Use -r to invert the sorting order.

ls -r
ls -r output
ls -r output

15. Recursive listing

Use -R to list directories and all of their descendants.

ls -R
ls -R output
ls -R output

16. Sort by extension

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

ls -lX
ls sorted by extension
ls sorted by extension

17. Sort by modification time

Use -t to list newest files first.

ls -lt
ls -lt output
ls -lt output

18. List home directory

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

ls ~
ls ~ output
ls ~ output

19. List parent directories

Use .. to refer to the parent directory; multiple .. components can be chained.

ls ../
ls ../../
ls parent directories
ls parent directories

20. Show version

Use --version to display the program version.

ls --version
ls version
ls version

Summary

These options cover the most common use‑cases for ls. For additional details, consult the manual page 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.

Linuxshellcommand linelsfile listingoptions
Linux Tech Enthusiast
Written by

Linux Tech Enthusiast

Focused on sharing practical Linux technology content, covering Linux fundamentals, applications, tools, as well as databases, operating systems, network security, and other technical 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.