Fundamentals 10 min read

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

This article provides a comprehensive guide to the Linux ls command, explaining its basic purpose and demonstrating twenty useful options—including long listing, human‑readable sizes, sorting, hidden files, recursive listing, and version display—complete with command examples and screenshot illustrations.

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

What is ls?

The ls command lists files and directories in the current directory. Adding options modifies its output for various everyday tasks.

1. Run ls without parameters

Executing ls with no flags shows only the names of files and directories.

$ ls

2. Long listing format

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

$ ls -l

Column 1: file type and permission bits.

Column 2: number of hard links.

Column 3: owner name.

Column 4: group name.

Column 5: size in bytes (directories are always 4096 bytes).

Column 6: last modification timestamp.

Column 7: file or directory name.

3. Human‑readable file sizes

Combine -h with -l to show sizes in a readable format (e.g., 6.5M instead of 6727680 bytes).

$ ls -lh

The --si flag works similarly but uses powers of 1000 instead of 1024.

$ ls -si

4. Sort by file size

Use -S to sort entries from largest to smallest.

$ ls -lhS

5. Specify block size

The --block-size=SIZE option changes the unit used for file sizes. Common suffixes are K (kilobyte), M (megabyte), G (gigabyte), T (terabyte), P (petabyte), E (exabyte), Z (zettabyte), Y (yottabyte).

$ 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 only directories

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

$ 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; -g already hides the owner.

$ ls -lG

10. Print numeric UID and GID

Use -n to display owners and groups as numeric IDs.

$ ls -n

In the example, user pungki has UID 100 and GID 1000, while the root group has GID 0.

11. Disable color output

Some distributions enable colored output by default; use --color=never to turn it off.

$ ls --color=never

12. Show inode numbers

Use -i to display each file’s inode number in the first column.

$ 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 direction.

$ 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 filename extension.

$ ls -lX

17. Sort by modification time

Use -t to sort newest files first.

$ ls -lt

18. List your home directory

Use the tilde ( ~) to refer to the current user’s home directory.

$ ls ~

19. List parent directories

Use ../ to show the directory one level up, or ../../ for two levels up.

$ ls ../
$ ls ../../

20. Show ls version

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

$ ls --version

For a complete reference, consult the manual page with man ls or ls --help.

Linuxshellcommand-linelsfile-listing
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.