Mastering the ls Command: 20 Essential Options for Linux File Listing
This guide explains the Linux ls command, its purpose, and walks through twenty practical options—including long format, human‑readable sizes, sorting, hidden files, recursive listing, and version display—so readers can list and interpret directory contents efficiently.
The ls command is a core Linux utility used to list files and directories; by default it shows the contents of the current directory. Mastering its many options lets users obtain detailed, sortable, and formatted views of the filesystem.
What is ls?
lslists directory entries. Without arguments it simply prints names, but with flags it can display permissions, owners, sizes, timestamps, and more.
Commonly Used Options
1. No parameters
Running ls without flags lists only names.
ls2. Long listing format
Use -l to show a detailed list with permissions, links, owner, group, size, modification time, and name.
ls -lThe columns represent:
File type and permissions (e.g., d for directory, - for file, l for symlink).
Number of hard links.
Owner name.
Group name.
Size in bytes (directories are typically 4096 B).
Last modification timestamp.
File or directory name.
3. Human‑readable sizes
Combine -h with -l to display sizes in KiB, MiB, etc.
ls -lhThe -si flag works similarly but uses decimal units (1000 B). Example:
ls -si4. Sort by size
Use -S (often together with -lh) to sort entries from largest to smallest.
ls -lhS5. Specify block size
Change the displayed unit with --block-size=SIZE (e.g., M for megabytes).
ls -l --block-size=M6. Show hidden files
Files beginning with a dot are hidden; -a reveals them.
ls -a7. List directories only
Use -d */ to display only directory entries.
ls -d */8. Omit owner information
Flag -g hides the owner column.
ls -g9. Omit group information
Use -G (or --group-directories-first in some shells) to hide the group column.
ls -lG10. Show numeric UID/GID
Flag -n prints owners and groups as numeric IDs.
ls -n11. Disable color output
Many distributions enable colored output; --color=never turns it off.
ls --color=never12. Print inode numbers
Use -i to show each file's index (inode) in the first column.
ls -li13. Append '/' to directories
Flag -p adds a trailing slash to directory names.
ls -p14. Reverse sort order
Use -r to invert the default sorting order.
ls -r15. Recursive listing
Flag -R lists sub‑directories recursively.
ls -R16. Sort by extension
Use -X or --sort=extension to order files by their suffix.
ls -lX17. Sort by modification time
Flag -t lists newest files first.
ls -lt18. List home directory
Use ~ as a shortcut for the current user's home.
ls ~19. List parent directory
Use ../ (or ../../ for two levels up) to view the directory above.
ls ../ ls ../../20. Show version
Flag --version prints the ls program version.
ls --versionConclusion
These options cover the most useful ways to tailor ls output for everyday tasks. For additional details, consult the manual pages with man ls or ls --help.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
