Fundamentals 10 min read

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

This guide introduces the Linux ls command, explains its basic purpose, and walks through twenty practical options—including long listings, human‑readable sizes, sorting, hidden files, recursive listing, and version display—complete with example commands and screenshots for each feature.

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

What is ls?

The ls command lists files and directories, showing the contents of the current directory by default; with options it can provide much more detailed information.

1. Run ls without arguments

Executing ls without parameters lists only file and directory names.

2. Long listing format

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

ls -l

Column 1: file type (d for directory, - for regular file, l for symlink)

Column 2: permission bits (rwx for owner, group, others)

Column 3: number of hard links

Column 4: owner name

Column 5: group name

Column 6: size in bytes (directories are 4096 B)

Column 7: last modification time

Column 8: file or directory name

3. Human‑readable sizes

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

ls -lh

4. Sort by size

Use -S to sort entries from largest to smallest.

ls -lhS

5. Display sizes with a specific block size

Specify a unit with --block-size=SIZE, e.g., ls -l --block-size=M to show sizes in megabytes.

ls -l --block-size=M

6. Show hidden files

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

ls -a

7. List only directories

Use -d */ to display directory entries without their contents.

ls -d */

8. Omit owner information

Use -g to hide the owner column.

ls -g

9. Omit group information

Use -G (capital G) 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 suppress colored listings.

ls --color=never

12. Show inode numbers

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

ls -li

13. Append ‘/’ to directories

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

ls -p

14. Reverse sort order

Use -r to reverse the default sorting 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 or

ls --sort=extension

17. Sort by modification time

Use -t to list newest files first.

ls -lt

18. List your home directory

Use ~ as a shortcut for the home path.

ls ~

19. List parent directories

Use .. to refer to the parent directory, e.g., ls ../ or ls ../../.

ls ../
ls ../../

20. Show ls version

Use --version to display the command’s version information.

ls --version

Summary

These options cover the most common uses of ls in daily work; you can always consult the manual page 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.

LinuxUnixfile-listingls command
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.