ls Command Deep Dive: 20 Practical Options for Linux File Management
This tutorial explores 20 practical ls command options for Linux, covering long listing, human-readable sizes, sorting by size or time, showing hidden files, inode numbers, recursive listing, and version information, with clear examples for each flag.
What is ls
The ls command lists files and directories. By default it shows the current directory's contents. With arguments, it can do much more. Here are common daily-use examples.
1. Run ls without arguments
Running ls alone lists only file or directory names, no extra information. (Note: if your ls behaves differently, it may be aliased with parameters.)
$ ls2. Use long listing format
The -l (lowercase L) option displays a detailed long list. This is frequently combined with other flags for better output. $ ls -l How to read the output:
Column 1 : First character indicates type: d = directory, - = file, l = symlink. Next nine characters are permissions: three for owner, three for group, three for others.
Column 2 : Number of hard links to the file.
Column 3 : File owner username.
Column 4 : File group name.
Column 5 : Size in bytes. Directories always show 4096 bytes.
Column 6 : Last modification timestamp.
Column 7 : File or directory name.
3. Show human-readable file sizes
Byte counts are hard to read. Use -h with -l for human-readable units (powers of 1024). $ ls -lh Alternatively, --si uses powers of 1000 instead of 1024.
$ ls -si4. Sort by file size
Add -S to sort largest first.
$ ls -lhS5. Specify block size units
Use --block-size=SIZE to set the display unit. Valid SIZE letters: K = Kilobyte M = Megabyte G = Gigabyte T = Terabyte P = Petabyte E = Exabyte Z = Zettabyte Y = Yottabyte
Example using megabytes:
$ ls -l --block-size=M6. Show hidden files
Files starting with . are hidden. Use -a to include them.
$ ls -a7. List only directories
Use -d */ to list directory entries without their contents.
$ ls -d */8. Omit owner information
The -g flag hides the owner column (like -l but without owner).
$ ls -g9. Omit group information
-G(capital G) hides the group column.
$ ls -lG10. Print numeric UID and GID
Use -n to show numeric user and group IDs instead of names. $ ls -n Example output shows user pungki has UID 100, GID 1000; root group has GID 0.
11. Disable colored output
Some distributions enable colors by default. Use --color=never to turn it off.
$ ls --color=never12. Print inode numbers
Add -i to show each file's inode (index number) in the first column.
$ ls -li13. Append slash to directories
The -p flag adds a trailing / to directory names for visual distinction.
$ ls -p14. Reverse sort order
Use -r to reverse whatever sorting is active (alphabetical, time, size, etc.).
$ ls -r15. Recursively list subdirectories
-Rlists the directory tree recursively.
$ ls -R16. Sort by file extension
Use -X or --sort=extension to group files by extension.
$ ls -lX
# or
$ ls --sort=extension17. Sort by modification time
-tsorts by modification time, newest first. Often combined with -l.
$ ls -lt18. List your home directory
The tilde ~ expands to the current user's home directory (e.g., /home/pungki).
$ ls ~19. List parent directories
Use ../ for the immediate parent, ../../ for two levels up, etc. (Note: ... is not supported.)
$ ls ../
$ ls ../../20. Print ls version
Use --version to display the version of the ls binary.
$ ls --versionConclusion
These are the most commonly used options for daily operations. For a complete reference, run 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.
