Master the Linux ls Command: 20 Essential Options Explained
This guide walks you through the Linux ls command, explaining its purpose and demonstrating twenty practical options—from basic listings and long format to sorting, hidden files, recursive traversal, and version info—so you can navigate and manage files efficiently.
What is ls
The ls command lists files and directories; by default it shows the contents of the current directory. Adding options extends its functionality for detailed views, sorting, filtering, and more.
Common usages
1. Run ls without options
$ ls2. Long listing format
Use -l to display a detailed list with permissions, links, owner, group, size, modification date, and name.
$ ls -l3. Human‑readable sizes
Combine -h with -l to show sizes in KB, MB, etc.
$ ls -lh4. Sort by size
Use -S to sort files from largest to smallest.
$ ls -lhS5. Block size unit
Specify a unit with --block-size=SIZE (e.g., --block-size=M for megabytes).
$ ls -l --block-size=M6. Show hidden files
Files beginning with a dot are hidden; use -a to display them.
$ ls -a7. List directories only
Use -d */ to list only directory entries.
$ ls -d */8. Omit owner information
Use -g to hide the owner column.
$ ls -g9. Omit group information
Use -G (or --no-group) to hide the group column.
$ ls -lG10. Show numeric UID/GID
Use -n to display numeric user and group IDs.
$ ls -n11. Disable color output
Use --color=never to turn off colored listings.
$ ls --color=never12. Show inode numbers
Use -i (or -li for long format) to display each file's inode.
$ ls -li13. Append slash to directories
Use -p to add a trailing / to directory names.
$ ls -p14. Reverse sort order
Use -r to reverse the listing order.
$ ls -r15. Recursive listing
Use -R to list subdirectories recursively.
$ ls -R16. Sort by extension
Use -X or --sort=extension to order files by their extensions.
$ ls -lX17. Sort by modification time
Use -t to list newest files first.
$ ls -lt18. List home directory
Use ~ as a shortcut for your home directory.
$ ls ~19. List parent directories
Use ../ (or ../../) to view one or two levels up.
$ ls ../20. Show version
Use --version to display the ls version.
$ ls --versionSummary
These options cover the most frequently used ls features; you can always consult the manual with man ls or ls --help for additional details.
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.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
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.
