Unlock the Power of ls: 20 Essential Options You Need to Know
This article provides a comprehensive guide to the Linux ls command, explaining its basic purpose and demonstrating twenty useful options—including long listing, human‑readable sizes, sorting, hidden files, recursive listing, and version display—complete with command examples and screenshot illustrations.
What is ls?
The ls command lists files and directories in the current directory. Adding options modifies its output for various everyday tasks.
1. Run ls without parameters
Executing ls with no flags shows only the names of files and directories.
$ ls2. Long listing format
Use -l (lower‑case L) to display a detailed list showing permissions, link count, owner, group, size, modification time, and name.
$ ls -lColumn 1: file type and permission bits.
Column 2: number of hard links.
Column 3: owner name.
Column 4: group name.
Column 5: size in bytes (directories are always 4096 bytes).
Column 6: last modification timestamp.
Column 7: file or directory name.
3. Human‑readable file sizes
Combine -h with -l to show sizes in a readable format (e.g., 6.5M instead of 6727680 bytes).
$ ls -lhThe --si flag works similarly but uses powers of 1000 instead of 1024.
$ ls -si4. Sort by file size
Use -S to sort entries from largest to smallest.
$ ls -lhS5. Specify block size
The --block-size=SIZE option changes the unit used for file sizes. Common suffixes are K (kilobyte), M (megabyte), G (gigabyte), T (terabyte), P (petabyte), E (exabyte), Z (zettabyte), Y (yottabyte).
$ ls -l --block-size=M6. Show hidden files
Files beginning with a dot ( .) are hidden; use -a to display them.
$ ls -a7. List only directories
Use -d */ to list 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 (capital G) to hide the group column; -g already hides the owner.
$ ls -lG10. Print numeric UID and GID
Use -n to display owners and groups as numeric IDs.
$ ls -nIn the example, user pungki has UID 100 and GID 1000, while the root group has GID 0.
11. Disable color output
Some distributions enable colored output by default; use --color=never to turn it off.
$ ls --color=never12. Show inode numbers
Use -i to display each file’s inode number in the first column.
$ 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 direction.
$ 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 filename extension.
$ ls -lX17. Sort by modification time
Use -t to sort newest files first.
$ ls -lt18. List your home directory
Use the tilde ( ~) to refer to the current user’s home directory.
$ ls ~19. List parent directories
Use ../ to show the directory one level up, or ../../ for two levels up.
$ ls ../ $ ls ../../20. Show ls version
Use --version to display the version of the ls utility.
$ ls --versionFor a complete reference, consult the manual page with man ls or ls --help.
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.
