Mastering the Linux ls Command: 20 Essential Options Explained
This guide walks you through the 20 most useful ls command options, showing how to list files, display detailed information, sort by size or time, show hidden items, format output, and more, with clear examples and screenshots for each feature.
The ls command is a fundamental tool for navigating and inspecting files and directories in Linux. Below are twenty practical options that extend its default behavior, each illustrated with example commands and screenshots.
1. List without parameters
Running ls without any flags simply lists the names of files and directories in the current directory.
ls2. Long listing format
Use the -l flag to display a detailed list, showing permissions, link count, owner, group, size, modification date, and name.
ls -l3. Human‑readable sizes
Combine -h with -l to show file sizes in a readable format (e.g., 6.5M instead of bytes).
ls -lh4. Sort by size
The -S flag sorts entries by size, largest first.
ls -lhS5. Specify block size
Use --block-size=SIZE to force a particular unit (K, M, G, etc.). Example:
ls -l --block-size=M6. Show hidden files
Files beginning with a dot are hidden; the -a option reveals them.
ls -a7. List only directories
The -d flag prevents descending into directories, showing only the directory entries themselves.
ls -d */8. Omit owner information
Use -g to hide the owner column while keeping group information.
ls -g9. Omit group information
Combine -l with -G (or use -lG) to hide the group column.
ls -lG10. Show numeric UID/GID
The -n option displays owners and groups as numeric IDs.
ls -n11. Disable color output
Some distributions colorize output; --color=never disables it.
ls --color=never12. Print inode numbers
Use -i to prepend each entry with its inode number.
ls -li13. Append slash to directories
The -p flag adds a trailing / to directory names.
ls -p14. Reverse sort order
Apply -r to reverse the default sorting order.
ls -r15. Recursive listing
With -R, ls lists subdirectories recursively.
ls -R16. Sort by extension
Use -X or --sort=extension to order files by their file‑type extension.
ls -lX ls --sort=extension17. Sort by modification time
The -t flag sorts entries so the most recently modified files appear first.
ls -lt18. List home directory
Use the tilde ~ shortcut to refer to the current user's home directory.
ls ~19. List parent directory
Navigate upward with ... For example, ls ../ lists the immediate parent, while ls ../../ lists two levels up.
ls ../ ls ../../20. Show ls version
Display the version of the ls utility with --version. ls --version For any of these options, you can always consult the manual page with man ls or view a quick help summary using 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.
