Fundamentals 10 min read

Unlock the Power of ls: 20 Essential Options You Need to Know

This article explains the Linux ls command in depth, covering twenty useful options—from basic listings and long format to sorting, recursive traversal, and displaying hidden files—complete with command examples, output screenshots, and tips for mastering file and directory inspection.

Linux Tech Enthusiast
Linux Tech Enthusiast
Linux Tech Enthusiast
Unlock the Power of ls: 20 Essential Options You Need to Know

ls command overview

The ls utility lists files and directories in a Linux filesystem. By default it shows the names in the current directory; additional options modify the output.

1. Run ls without options

$ ls
ls output
ls output

2. Long listing format

Use -l (lower‑case L) to display permissions, link count, owner, group, size, modification time and name.

$ ls -l
ls -l output
ls -l output

Column interpretation:

1: file type (d for directory, - for regular file, l for symlink) and permission bits (rwx for owner, group, others).

2: number of hard links.

3: owner name.

4: group name.

5: size in bytes (directories typically 4096 bytes).

6: last modification timestamp.

7: file or directory name.

3. Human‑readable file sizes

Combine -h with -l to show sizes in K, M, G instead of raw bytes.

$ ls -lh
ls -lh output
ls -lh output

The --si flag uses powers of 1000 rather than 1024.

$ ls --si
ls --si output
ls --si output

4. Sort by file size

Use -S to order entries from largest to smallest.

$ ls -lhS
ls sorted by size
ls sorted by size

5. Custom block size

The --block-size=SIZE option sets the unit (K, M, G, …). Example: display sizes in megabytes.

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

6. Show hidden files

Files beginning 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 their contents.

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

8. Omit owner information

The -g flag hides the owner column.

$ ls -g
ls -g output
ls -g output

9. Omit group information

The -G (or --group-directories-first in some shells) hides the group column.

$ ls -lG
ls -lG output
ls -lG output

10. Print numeric UID and GID

Use -n to display numeric user and group IDs.

$ ls -n
ls -n output
ls -n output

Example shows user pungki with UID 100, GID 1000; the root group has GID 0.

11. Disable colored output

Some distributions enable color by default; suppress it with --color=never.

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

12. Print inode numbers

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

$ ls -li
ls -li output
ls -li output

13. Append '/' to directories

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

$ ls -p
ls -p output
ls -p output

14. Reverse sort order

Use -r to reverse the default sorting order.

$ ls -r
ls -r output
ls -r output

15. Recursively list subdirectories

The -R option traverses directories recursively.

$ ls -R
ls -R output
ls -R output

16. Sort by extension

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

$ ls -lX
ls sorted by extension
ls sorted by extension

17. Sort by modification time

The -t flag orders entries by newest modification time first.

$ ls -lt
ls sorted by time
ls sorted by time

18. List your 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 view the immediate parent directory, or ../../ for the grand‑parent.

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

20. Print ls version

Use --version to display the version information of the ls utility.

$ ls --version
ls version output
ls version output

These options cover the most commonly used ls parameters for everyday tasks. The manual page ( man ls) or ls --help provides a complete reference.

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-lineterminallsfile listingUnix utilities
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.