The ls command in Linux

The ls command lists the contents of a directory. It is almost certainly the command you will run most often in a Linux terminal: before you move, copy, delete or open anything, you usually run ls first to see what is there. By default it lists the current directory in alphabetical order, hiding any file whose name starts with a dot.

How ls works

A directory in Linux is itself a file — one whose contents are a list of name-to-inode pairs. When you run ls, it opens that directory file and reads out the names. That is all a plain ls does, which is why it is instantaneous even in a directory of a million entries: it never touches the files themselves.

The long listing is a different animal. Sizes, permissions, owners and dates do not live in the directory — they live in each file's inode. So ls -l must call stat() once per entry to fetch that metadata, which is why -l is visibly slower on huge or network-mounted directories. One more thing worth internalizing: when you type ls *.txt, the shell — not ls — expands the wildcard and passes the resulting names as arguments. ls never sees the asterisk. This "the shell expands globs" rule explains dozens of otherwise mysterious behaviors across every command.

Syntax

ls [OPTIONS] [PATH...]

Common options

OptionWhat it does
-lLong format: permissions, owner, group, size and modification date of each entry.
-aShow all files, including hidden ones (names starting with a dot, like .bashrc).
-hWith -l, print sizes in human-readable units (K, M, G) instead of bytes.
-tSort by modification time, newest first.
-rReverse the sort order.
-RList subdirectories recursively.
-SSort by file size, largest first.
-dList the directory itself instead of its contents (useful with wildcards).

How to use ls: examples

$ ls

List the current directory. Directories are usually shown in a different color.

$ ls -l

Long listing. The first column shows the type and permissions: d means directory, - means regular file.

$ ls -la

Long listing including hidden files. This is one of the most common option combinations in daily use.

$ ls -lh

Long listing with human-readable sizes: 4.0K, 12M, 1.2G instead of raw byte counts.

$ ls -lt

Sort by modification time so the most recently changed files appear at the top. Add -r (ls -ltr) to put the newest at the bottom, right above your prompt.

$ ls /var/log

You can list any path without moving to it first.

$ ls -d */

Show only the directories in the current location.

$ ls *.txt

Use wildcards to list only files matching a pattern.

Real-world use cases for ls

Auditing a server directory

You SSH into a server and need to know what changed recently: ls -lt shows files by modification time, newest first, and ls -lah adds hidden files and readable sizes. Within seconds you know what was touched, when, and how big it is — before opening a single file.

Checking permissions before a deploy

A web deploy fails with 403 errors. ls -l on the web root instantly shows whether files are readable (644) and directories enterable (755), and who owns them. Most permission incidents are diagnosed with ls -l alone, before chmod is ever needed.

Try ls yourself

This is a live sandbox with a small filesystem (documents/, notes.txt, backup.sh…). Nothing you do here can break anything — experiment freely. Try: ls -la

Pro tips and common mistakes

Frequently asked questions about ls

What does ls -la show?

ls -la combines two options: -l prints a detailed (long) listing with permissions, owner, size and date, and -a includes hidden files — those whose names begin with a dot, such as .bashrc or .gitignore.

How do I sort ls output by date?

Use ls -lt to sort by modification time with the newest first. Many users prefer ls -ltr, which reverses the order so the most recent files appear at the bottom, directly above the prompt.

Why are some files not shown by ls?

By default ls hides any file whose name starts with a dot. These are conventionally used for configuration. Run ls -a to include them.

Related commands

cd

Move between directories: absolute and relative paths, home shortcut, and jumping back.

pwd

Show the absolute path of the directory you are currently in.

cat

Print file contents, number lines, and join multiple files together.

find

Locate files anywhere in a directory tree by name, type, size, date — and act on them.

Want to build real fluency? The interactive course takes you through ls and every other essential command with guided, checked exercises.