Linux command list

ls command: list files and directories

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying ls. Nothing here can touch your real files.
user@webterm:~/project$
 

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

Syntax

ls [options] [file or directory]

Running ls with no arguments lists the current directory. Passing a directory name lists that directory instead.

Try it first

The terminal on this page starts inside a small project directory. Typing ls prints this:

$ ls
docs/  logs/  package.json  README.md  src/

The options worth knowing

OptionWhat it does
-lOne entry per line, with permissions, owner, size, and modification time
-aInclude hidden entries, whose names begin with a dot
-hPrint sizes with a unit, such as 19K (use together with -l)
-RDescend into subdirectories and list those too
-tSort by modification time, newest first
-SSort by size, largest first
-rReverse the sort order
-dShow the directory itself rather than its contents
-1Print one entry per line (the digit one)

Short options can be combined. ls -l -a and ls -la mean the same thing.

When you actually reach for it

ls is the command you type without thinking, but the option you add depends on what you are after.

What you want to knowWhat to typeWhere to look
Which log is the newestls -ltrThe last line is the most recently changed file
What is eating disk spacels -lhSLargest files first
Whether permissions are rightls -lThe rwx block on the left
Whether a config file existsls -aEntries beginning with a dot
How a tree is laid outls -RThe 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.

Reading the output of ls -l

With -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:

ColumnExampleMeaning
Type and permissions-rw-r--r--One character of type, then nine of permissions
Link count1How many hard links point at the file
OwneruserThe user who owns the file
GroupuserThe group the file belongs to
Size46Size in bytes
ModifiedSep 4 21:08When the contents last changed
Namepackage.jsonThe 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.

Showing hidden 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.

Making sizes readable

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

Finding the biggest files

-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

Listing everything underneath

-R walks down into each subdirectory.

$ ls -R
.:
docs/  logs/  package.json  README.md  src/

./docs:

./logs:
app.log

./src:
index.js  utils.js

Things that trip people up

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.

Practise it hands-on

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

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

Related commands

cd / pwd / tree / stat / find

Frequently asked questions

What does ls stand for?
It is short for list. The command lists the names of the files and directories inside a directory.
Why are some of my files missing from the output?
Files whose names start with a dot are hidden from ls by default. Configuration files such as .env and .gitignore work this way. Add -a to show them.
What is the -rw-r--r-- at the start of each ls -l line?
The first character is the type (- for a regular file, d for a directory, l for a symbolic link). The remaining nine characters are the permissions, in three groups of three: owner, group, and others. Each group shows read r, write w, and execute x, or a dash when that permission is not granted.
How do I show file sizes in a readable form?
Use ls -lh. On its own, -l prints the size in bytes; adding -h prints it with a unit, such as 19K or 2.3M.
Why does ls not work in the Windows Command Prompt?
ls is a Linux and macOS command and is not part of the Windows Command Prompt. The equivalent there is dir. In PowerShell, ls works as an alias for Get-ChildItem.
How do I print one entry per line?
Use ls -1, with the digit one. This makes the output easier to pipe into another command.