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.
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 -lColumn 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 -lh4. Sort by size
Use -S to sort entries from largest to smallest.
ls -lhS5. 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=M6. Show hidden files
Files beginning with a dot are hidden; use -a to list them.
ls -a7. 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 -g9. Omit group information
Use -G (capital G) 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 suppress colored listings.
ls --color=never12. Show inode numbers
Use -i to prepend the inode number to each entry.
ls -li13. Append ‘/’ to directories
Use -p to add a trailing slash to directory names.
ls -p14. Reverse sort order
Use -r to reverse the default sorting 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 -lX or
ls --sort=extension17. Sort by modification time
Use -t to list newest files first.
ls -lt18. 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 --versionSummary
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.
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.
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.
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.
