Unlock the Power of ls: 20 Essential Options You Need to Know
This article explains the Linux ls command in depth, covering twenty useful options—from basic listings and long format to sorting, recursive traversal, and displaying hidden files—complete with command examples, output screenshots, and tips for mastering file and directory inspection.
ls command overview
The ls utility lists files and directories in a Linux filesystem. By default it shows the names in the current directory; additional options modify the output.
1. Run ls without options
$ ls2. Long listing format
Use -l (lower‑case L) to display permissions, link count, owner, group, size, modification time and name.
$ ls -lColumn interpretation:
1: file type (d for directory, - for regular file, l for symlink) and permission bits (rwx for owner, group, others).
2: number of hard links.
3: owner name.
4: group name.
5: size in bytes (directories typically 4096 bytes).
6: last modification timestamp.
7: file or directory name.
3. Human‑readable file sizes
Combine -h with -l to show sizes in K, M, G instead of raw bytes.
$ ls -lhThe --si flag uses powers of 1000 rather than 1024.
$ ls --si4. Sort by file size
Use -S to order entries from largest to smallest.
$ ls -lhS5. Custom block size
The --block-size=SIZE option sets the unit (K, M, G, …). Example: display sizes in megabytes.
$ ls -l --block-size=M6. Show hidden files
Files beginning with a dot (.) are hidden; -a lists them.
$ ls -a7. List only directories
Use -d */ to display directory entries without their contents.
$ ls -d */8. Omit owner information
The -g flag hides the owner column.
$ ls -g9. Omit group information
The -G (or --group-directories-first in some shells) hides the group column.
$ ls -lG10. Print numeric UID and GID
Use -n to display numeric user and group IDs.
$ ls -nExample shows user pungki with UID 100, GID 1000; the root group has GID 0.
11. Disable colored output
Some distributions enable color by default; suppress it with --color=never.
$ ls --color=never12. Print inode numbers
Use -i to show each file's inode in the first column.
$ ls -li13. Append '/' to directories
The -p flag adds a trailing slash to directory names.
$ ls -p14. Reverse sort order
Use -r to reverse the default sorting order.
$ ls -r15. Recursively list subdirectories
The -R option traverses directories recursively.
$ ls -R16. Sort by extension
Use -X or --sort=extension to order files by their filename extensions.
$ ls -lX17. Sort by modification time
The -t flag orders entries by newest modification time first.
$ ls -lt18. List your home directory
Use the tilde ( ~) as a shortcut for the current user's home directory.
$ ls ~19. List parent directories
Use ../ to view the immediate parent directory, or ../../ for the grand‑parent.
$ ls ../
$ ls ../../20. Print ls version
Use --version to display the version information of the ls utility.
$ ls --versionThese options cover the most commonly used ls parameters for everyday tasks. The manual page ( man ls) or ls --help provides a complete reference.
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.
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.
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.
