Mastering the ls Command: 20 Essential Options You Need to Know
This guide walks through the Linux ls command, explaining its basic behavior and demonstrating 20 useful options—including long listing, human‑readable sizes, sorting, hidden files, recursive listing, and version display—so readers can list files and directories more effectively.
ls command overview
The ls utility lists files and directories in the current working directory. By default it prints only the names; adding options changes the format, sorting, and displayed metadata.
1. Run without arguments
Simply typing ls lists the entries in the current directory.
ls2. Long listing format
Use -l to display a detailed list that includes permissions, link count, owner, group, size, modification time, and name.
ls -lThe columns are interpreted as follows:
Column 1 – file type (d for directory, – for regular file, l for symlink) and permission bits.
Column 2 – number of hard links.
Column 3 – owner name.
Column 4 – group name.
Column 5 – size in bytes (directories usually report 4096 bytes).
Column 6 – last modification timestamp.
Column 7 – file or directory name.
3. Human‑readable sizes
Combine -h with -l to show sizes in KiB, MiB, etc.
ls -lhThe --si option works like -h but uses powers of 1000 instead of 1024.
ls -si4. Sort by file size
Use -S (often together with -lh) to sort entries from largest to smallest.
ls -lhS5. Custom block size
Specify --block-size=SIZE to display sizes in a chosen unit (e.g., M for megabytes).
ls -l --block-size=M6. Show hidden files
Files whose names start with a dot are hidden; -a lists them.
ls -a7. List only directories
Use -d */ to display directory entries without recursing into them.
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. Numeric UID/GID
Use -n to display numeric user and group IDs.
ls -n11. Disable colorized output
Some distributions enable color; --color=never turns it off.
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 invert the sorting order.
ls -r15. Recursive listing
Use -R to list directories and all of their descendants.
ls -R16. Sort by extension
Use -X or --sort=extension to group files by their extensions.
ls -lX17. Sort by modification time
Use -t to list newest files first.
ls -lt18. List home directory
Use the tilde ~ as a shortcut for the current user's home directory.
ls ~19. List parent directories
Use .. to refer to the parent directory; multiple .. components can be chained.
ls ../
ls ../../20. Show version
Use --version to display the program version.
ls --versionSummary
These options cover the most common use‑cases for ls. For additional details, consult the manual page 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.
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.
