ls prints what is inside a directory. Learn what -l and -a do, and how to read every column of ls -l, by typing the commands in a real terminal in your browser.
Updated: 2026-09-04
ls [options] [file or directory]
Running ls with no arguments lists the current directory.
Passing a directory name lists that directory instead.
The terminal on this page starts inside a small project directory.
Typing ls prints this:
$ ls
docs/ logs/ package.json README.md src/
| Option | What it does |
|---|---|
-l | One entry per line, with permissions, owner, size, and modification time |
-a | Include hidden entries, whose names begin with a dot |
-h | Print sizes with a unit, such as 19K (use together with -l) |
-R | Descend into subdirectories and list those too |
-t | Sort by modification time, newest first |
-S | Sort by size, largest first |
-r | Reverse the sort order |
-d | Show the directory itself rather than its contents |
-1 | Print one entry per line (the digit one) |
Short options can be combined. ls -l -a and ls -la mean the same thing.
ls is the command you type without thinking, but the option you add depends on what you are after.
| What you want to know | What to type | Where to look |
|---|---|---|
| Which log is the newest | ls -ltr | The last line is the most recently changed file |
| What is eating disk space | ls -lhS | Largest files first |
| Whether permissions are right | ls -l | The rwx block on the left |
| Whether a config file exists | ls -a | Entries beginning with a dot |
| How a tree is laid out | ls -R | The per-directory headings |
ls -ltr earns its place. Sorting by time (-t) and reversing it (-r) puts the most recently changed file at the bottom, so in a busy directory the newest file is visible without scrolling.
ls -lWith -l, each entry gets a line of detail.
$ ls -l
total 20
drwxr-xr-x 2 user user 4096 Sep 4 21:08 docs/
drwxr-xr-x 2 user user 4096 Sep 4 21:08 logs/
-rw-r--r-- 1 user user 46 Sep 4 21:08 package.json
-rw-r--r-- 1 user user 36 Sep 4 21:08 README.md
drwxr-xr-x 2 user user 4096 Sep 4 21:08 src/
Taking the package.json line from left to right:
| Column | Example | Meaning |
|---|---|---|
| Type and permissions | -rw-r--r-- | One character of type, then nine of permissions |
| Link count | 1 | How many hard links point at the file |
| Owner | user | The user who owns the file |
| Group | user | The group the file belongs to |
| Size | 46 | Size in bytes |
| Modified | Sep 4 21:08 | When the contents last changed |
| Name | package.json | The file name |
That leading -rw-r--r-- splits into four parts:
- rw- r-- r--
type owner group others
The type is - for a regular file, d for a directory, and l for a symbolic link.
Each of the three groups that follow shows read r, write w, and execute x when granted, and - when not.
So -rw-r--r-- means a regular file that the owner can read and write, while the group and everyone else can only read.
The total 20 on the first line is the number of blocks the directory uses.
It is not a count of files.
Entries beginning with a dot do not appear by default.
Configuration files usually take that form, so reach for -a whenever a file you expect is missing.
$ ls
docs/ logs/ package.json README.md src/
$ ls -a
./ ../ .env .gitignore docs/ logs/ package.json README.md src/
Here ./ is the directory itself and ../ is the one above it.
On its own, -l reports bytes.
Adding -h attaches a unit.
$ ls -lh logs
total 20
-rw-r--r-- 1 user user 19K Sep 4 21:09 app.log
-S sorts by size, largest first.
Adding -l and -h turns that into a readable answer to "what is taking up the space".
$ ls -lhS logs
total 20
-rw-r--r-- 1 user user 19K Sep 4 21:09 app.log
-R walks down into each subdirectory.
$ ls -R
.:
docs/ logs/ package.json README.md src/
./docs:
./logs:
app.log
./src:
index.js utils.js
An unknown name is an error, not an empty result.
$ ls nothing
ls: cannot access 'nothing': No such file or directory
Either the name is a typo, or the current directory is not the one you assumed.
Run pwd to check where you are, then try again.
-d is not much use on its own.
It exists to describe the directory rather than its contents, so it is normally paired with -l, as in ls -ld src.
The default order is by name.
-t switches to modification time, and adding -r flips it to oldest first.
ls -ltr therefore puts the most recently changed file at the bottom, which is why it is a common way to look at logs.
Terminal for Beginners
Learn basic commands
Terminal Fundamentals
Learn commonly used commands

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the course