Fundamentals 9 min read

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.

Linux Tech Enthusiast
Linux Tech Enthusiast
Linux Tech Enthusiast
ls Command Deep Dive: 20 Practical Options for Linux File Management

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.)

$ ls

2. 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 -si

4. Sort by file size

Add -S to sort largest first.

$ ls -lhS

5. 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=M

6. Show hidden files

Files starting with . are hidden. Use -a to include them.

$ ls -a

7. 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 -g

9. Omit group information

-G

(capital G) hides the group column.

$ ls -lG

10. 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=never

12. Print inode numbers

Add -i to show each file's inode (index number) in the first column.

$ ls -li

13. Append slash to directories

The -p flag adds a trailing / to directory names for visual distinction.

$ ls -p

14. Reverse sort order

Use -r to reverse whatever sorting is active (alphabetical, time, size, etc.).

$ ls -r

15. Recursively list subdirectories

-R

lists the directory tree recursively.

$ ls -R

16. Sort by file extension

Use -X or --sort=extension to group files by extension.

$ ls -lX
# or
$ ls --sort=extension

17. Sort by modification time

-t

sorts by modification time, newest first. Often combined with -l.

$ ls -lt

18. 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 --version

Conclusion

These are the most commonly used options for daily operations. For a complete reference, run man ls or ls --help.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxshellcommand-linetutorialsystem-administrationterminallsfile-listing
Linux Tech Enthusiast
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.