Sitemap
Tengeeks

Tengeeks

Tech Blogger | AI • Technology • Programming • Cybersecurity | Simplifying the Future of Tech

Linux ls Command: Complete Guide to Listing Files and Directories

8 min readSep 23, 2026

--

Learn the Linux ls command from beginner to advanced level with practical examples, options, hidden files, permissions, file sizes, sorting, wildcards, and troubleshooting tips.

The Linux ls command is one of the most important terminal commands for beginners, system administrators, developers, DevOps engineers, and Linux professionals.

It allows you to list files and directories, view hidden files, check file permissions, inspect ownership, view file sizes, sort files, identify symbolic links, and examine directory contents directly from the Linux terminal.

Whether you use Ubuntu, Debian, Fedora, RHEL, Rocky Linux, AlmaLinux, CentOS, or another Linux distribution, learning ls is an essential part of learning Linux.

In this complete guide, you’ll learn:

  • What the Linux ls command does
  • ls command syntax
  • How to list files and directories
  • How to show hidden files
  • How to use ls -l
  • How to display human-readable file sizes
  • How to sort files
  • How to use wildcards
  • How to inspect permissions
  • How to display inode numbers
  • How to list directories recursively
  • Useful ls command combinations
  • Practical Linux examples
  • A complete ls options cheat sheet

What Is the Linux ls Command?

The ls command in Linux is used to display the contents of a directory.

The simplest command is:

ls

For example:

ls

A typical result might look like:

Desktop

Documents

Downloads

Music

Pictures

Videos

The actual output depends on the files and directories available in your current location.

The ls command is similar to viewing a folder in a graphical file manager, but it provides much more flexibility when used with different options.

Linux ls Command Syntax

The basic syntax is:

ls [OPTION]... [FILE]...

Common examples include:

ls

ls -l

ls -a

ls -lh

ls -lah

ls /etc

ls /var/log

Options change the information displayed by the command.

1. Basic Linux ls Command

To list the contents of the current directory, run:

ls

For example:

ls

Possible output:

Documents

Downloads

Pictures

Projects

notes.txt

script.sh

If you want to know your current location first, use:

pwd

Example:

pwd

Output:

/home/user

Then:

ls

will display the contents of /home/user.

2. List a Specific Directory

You can provide a directory path directly to the ls command.

For example:

ls /etc

This lists the contents of /etc.

Another common example is:

ls /var/log

This displays files inside the Linux log directory.

You can also use:

ls /home/user

This is useful because you don’t need to change directories with cd first.

3. Linux ls -l Command

The -l option displays a long listing format.

Use:

ls -l

Example:

drwxr-xr-x 2 user user 4096 Sep 23 10:20 Documents

-rw-r--r-- 1 user user 245 Sep 23 10:15 notes.txt

-rwxr-xr-x 1 user user 1820 Sep 23 09:50 script.sh

This output contains considerably more information than a normal ls command.

Understanding ls -l Output

Consider this example:

-rw-r--r-- 1 user user 245 Sep 23 10:15 notes.txt

The output contains several fields.

File Type

The first character identifies the file type.

- means regular file.

d means directory.

l commonly indicates a symbolic link.

File Permissions

The permission section may look like:

rw-r--r--

It represents permissions for:

  • File owner
  • Group
  • Other users

The common permission characters are:

  • r = read
  • w = write
  • x = execute

Owner

The owner field identifies the user who owns the file.

Group

The group field identifies the group associated with the file.

File Size

The size field shows the file size.

Modification Time

This shows when the file was last modified.

File Name

The final field is the name of the file or directory.

Understanding ls -l output is especially useful when troubleshooting Linux permissions and ownership problems.

4. Show Hidden Files Using ls -a

Linux uses a dot at the beginning of a filename to indicate hidden files.

Examples include:

.bashrc

.profile

.config

.ssh

If you run:

ls

these files normally won’t appear.

To show hidden files, use:

ls -a

Example:

.

..

.bashrc

.config

Documents

Downloads

notes.txt

The -a option means all.

The entries . and .. have special meanings:

. represents the current directory.

.. represents the parent directory.

5. Use ls -lh for Human-Readable File Sizes

The -h option displays file sizes in a human-readable format.

Instead of seeing large numbers representing bytes, you can see values such as:

2.4K

15M

1.2G

Use:

ls -lh

Example:

-rw-r--r-- 1 user user 2.4K Sep 23 10:15 notes.txt

-rw-r--r-- 1 user user 15M Sep 23 09:50 backup.zip

This is one of the most useful ls options for everyday Linux administration.

6. Use ls -lah to See Almost Everything

One of the most useful combinations is:

ls -lah

It combines:

-l — long listing

-a — show hidden files

-h — human-readable file sizes

For example:

ls -lah

This gives you detailed information about both normal and hidden files while keeping file sizes easy to read.

Another common form is:

ls -alh

Both forms are commonly used.

7. Sort Files by Modification Time

The -t option sorts files by modification time.

Use:

ls -lt

This can help you identify recently modified files.

For example, when troubleshooting an application, you can use:

ls -lt /var/log

to inspect recently modified log files.

To reverse the order:

ls -ltr

The r option reverses the sorting order.

8. List Files Recursively

The uppercase -R option lists directories recursively.

Use:

ls -R

For example:

ls -R Projects

This displays the contents of Projects and its subdirectories.

Be careful when using recursive listing on large directory structures because the output can become very long.

9. Display Inode Numbers

Linux file systems use inode numbers to identify files.

You can display inode numbers with:

ls -i

Example:

123456 notes.txt

Get Tengeeks’s stories in your inbox

Join Medium for free to get updates from this writer.

123457 script.sh

Inode information can be useful when troubleshooting file-system issues, hard links, and other Linux storage-related problems.

10. Show File Type Indicators

The -F option adds a character to filenames to indicate their type.

Use:

ls -F

You may see:

Documents/

script.sh*

link@

The indicators can help you quickly identify directories, executable files, and symbolic links.

11. List Directories Only

To list directories in the current location, use:

ls -d */

Example output:

Documents/

Downloads/

Pictures/

Projects/

This is useful when you only want to see directories rather than all files.

12. Use Wildcards With ls

The Linux shell supports wildcard patterns.

For example:

ls *.txt

This lists files ending with .txt.

To list log files:

ls *.log

To list files beginning with backup:

ls backup*

Wildcards make it much easier to work with directories containing many files.

13. List Configuration Files

Linux administrators often work with configuration files.

To list .conf files:

ls *.conf

For example:

apache.conf

database.conf

network.conf

server.conf

This can be particularly useful in configuration directories.

14. Inspect a Specific File

You can provide a specific filename:

ls -l notes.txt

Example:

-rw-r--r-- 1 user user 245 Sep 23 10:15 notes.txt

This lets you quickly check:

  • Permissions
  • Owner
  • Group
  • File size
  • Modification time

15. Sort Files by Size

The -S option sorts files by size.

Use:

ls -lS

This can help identify large files in a directory.

For human-readable sizes:

ls -lhS

This is particularly useful when investigating disk usage.

16. Sort by File Extension

The -X option sorts files by extension.

Use:

ls -lX

This can help group files with similar extensions together.

For example, .conf, .log, .txt, and .sh files can be grouped according to their names and extensions.

17. Useful ls Command Combinations

Here are some useful combinations to remember.

Basic listing

ls

Detailed listing

ls -l

Show hidden files

ls -a

Human-readable sizes

ls -lh

Detailed hidden files

ls -la

Detailed hidden files with readable sizes

ls -lah

Sort by modification time

ls -lt

Reverse time sorting

ls -ltr

Sort by file size

ls -lS

Recursive listing

ls -R

Show inode numbers

ls -i

Show file type indicators

ls -F

List directories

ls -d */

18. Practical Linux ls Examples

Find recently modified files

Use:

ls -lt

This puts recently modified files near the beginning of the output.

Check hidden configuration files

Use:

ls -la

This is especially useful in a Linux user’s home directory.

Check file sizes

Use:

ls -lh

This provides an easy-to-read view of file sizes.

Check Linux log files

Use:

ls -lh /var/log

This provides useful information about files stored in the Linux logging directory.

Find large files in a directory

Use:

ls -lhS

This sorts the listing by file size.

Check permissions

Use:

ls -l

Then inspect the permissions column.

For example:

-rwxr-xr--

This tells you how the file can be accessed by the owner, group, and other users.

19. Linux ls Command Cheat Sheet

CommandPurposelsList filesls -lDetailed listingls -aShow hidden filesls -hHuman-readable sizesls -lhDetailed listing with readable sizesls -laDetailed listing including hidden filesls -lahDetailed hidden listing with readable sizesls -ltSort by modification timels -ltrReverse time sortingls -lSSort by file sizels -RRecursive listingls -iShow inode numbersls -FShow file type indicatorsls -d */List directoriesls -lXSort by file extension

20. Common Beginner Mistakes With ls

Mistake 1: Expecting hidden files to appear

This command:

ls

does not normally show hidden files.

Use:

ls -a

instead.

Mistake 2: Confusing -R and -r

Linux command options are case-sensitive.

-R

means recursive listing.

-r

means reverse sorting.

These are completely different options.

Mistake 3: Forgetting -h

The output from:

ls -l

can contain raw byte sizes.

Using:

ls -lh

makes the sizes easier to understand.

Mistake 4: Using ls -R on huge directories

Recursive listings can produce a large amount of terminal output.

Use the option carefully when working with large file systems.

Frequently Asked Questions About the Linux ls Command

What is the ls command in Linux?

The ls command lists files and directories in Linux. It can also display permissions, ownership, file sizes, timestamps, inode numbers, and other information.

How do I show hidden files in Linux?

Use:

ls -a

For detailed information:

ls -la

What does ls -l do?

The -l option displays files in long listing format, including permissions, ownership, file size, and modification information.

What does ls -lh mean?

ls -lh displays a detailed listing with human-readable file sizes.

How do I sort files by modification time?

Use:

ls -lt

How do I find the largest files in a directory?

Use:

ls -lhS

This sorts files by size.

How do I list directories only?

Use:

ls -d */

What is the difference between -r and -R?

-r reverses the sorting order, while -R performs a recursive listing.

How do I display inode numbers?

Use:

ls -i

Final Thoughts

The Linux ls command is simple enough for beginners but powerful enough for everyday system administration.

Start with these commands:

ls

ls -l

ls -a

ls -lh

ls -lah

Then learn:

ls -lt

ls -ltr

ls -lhS

ls -R

ls -i

ls -F

With regular practice, you’ll quickly become comfortable navigating and inspecting Linux file systems from the terminal.

If you want more practical Linux tutorials, command guides, programming tutorials, AI tools, cybersecurity guides, and technology content, visit TenGeeks:

TenGeeks — Technology, AI, Linux & Programming Guides
https://tengeeks.blogspot.com/

--

--

Tengeeks
Tengeeks

Written by Tengeeks

Tech Blogger | AI • Technology • Programming • Cybersecurity | Simplifying the Future of Tech