ls: list the files in a folder
ls lists what is in a folder. It is the command you will type more than any other, and it changes nothing, so it is safe to experiment with.
The plain listing
asha@pc:~/demo$ ls
log.txt
marks.csv
notes.txt
old
photos
report.txtJust names, in alphabetical order. On most systems folders and files are shown in different colours.
The long listing
-l gives one line per item, with details.
asha@pc:~/demo$ ls -l
total 4
-rw-r--r-- 1 asha asha 222 Nov 1 15:00 log.txt
-rw-r--r-- 1 asha asha 53 Nov 1 15:00 marks.csv
-rw-r--r-- 1 asha asha 51 Nov 1 15:00 notes.txt
drwxr-xr-x 1 asha asha 0 Nov 1 15:00 old
drwxr-xr-x 1 asha asha 0 Nov 1 15:00 photos
-rw-r--r-- 1 asha asha 94 Nov 1 15:00 report.txtReading one line from the left:
| Part | Meaning |
|---|---|
-rw-r--r-- | the type and the permissions. A leading d means a folder, - an ordinary file |
1 | the number of links, which you can ignore |
asha asha | the owner and the group |
51 | the size in bytes |
Nov 1 15:00 | when it was last changed |
notes.txt | the name |
The permission letters are explained on the page about chmod.
Hidden files
Names that begin with a dot are hidden from a plain ls. Settings files are usually named this way. -a shows all.
asha@pc:~/demo$ touch .settings
asha@pc:~/demo$ ls
log.txt
marks.csv
notes.txt
old
photos
report.txt
asha@pc:~/demo$ ls -a
.
..
.settings
log.txt
marks.csv
notes.txt
old
photos
report.txtThe entries . and .. mean this folder and the one above it.
Sizes people can read
-h, with -l, shows sizes as K, M and G instead of plain bytes.
asha@pc:~/demo$ ls -lh
total 4.0K
-rw-r--r-- 1 asha asha 222 Nov 1 15:00 log.txt
-rw-r--r-- 1 asha asha 53 Nov 1 15:00 marks.csv
-rw-r--r-- 1 asha asha 51 Nov 1 15:00 notes.txt
drwxr-xr-x 1 asha asha 0 Nov 1 15:00 old
drwxr-xr-x 1 asha asha 0 Nov 1 15:00 photos
-rw-r--r-- 1 asha asha 94 Nov 1 15:00 report.txtNewest first
-t sorts by time, newest first. -r reverses any order. Together, -ltr puts the most recently changed file at the bottom, next to the prompt, which is where you want it in a long folder.
asha@pc:~/demo$ ls -lt
total 4
-rw-r--r-- 1 asha asha 222 Nov 1 15:00 log.txt
-rw-r--r-- 1 asha asha 53 Nov 1 15:00 marks.csv
-rw-r--r-- 1 asha asha 51 Nov 1 15:00 notes.txt
drwxr-xr-x 1 asha asha 0 Nov 1 15:00 old
drwxr-xr-x 1 asha asha 0 Nov 1 15:00 photos
-rw-r--r-- 1 asha asha 94 Nov 1 15:00 report.txtSort by size with -S, largest first.
asha@pc:~/demo$ ls -lS
total 4
-rw-r--r-- 1 asha asha 222 Nov 1 15:00 log.txt
-rw-r--r-- 1 asha asha 94 Nov 1 15:00 report.txt
-rw-r--r-- 1 asha asha 53 Nov 1 15:00 marks.csv
-rw-r--r-- 1 asha asha 51 Nov 1 15:00 notes.txt
drwxr-xr-x 1 asha asha 0 Nov 1 15:00 old
drwxr-xr-x 1 asha asha 0 Nov 1 15:00 photosAnother folder, and patterns
asha@pc:~/demo$ ls photos
beach.jpg
hills.jpg
asha@pc:~/demo$ ls *.txt
log.txt
notes.txt
report.txt
asha@pc:~/demo$ ls -l photos/*.jpg
-rw-r--r-- 1 asha asha 39 Nov 1 15:00 photos/beach.jpg
-rw-r--r-- 1 asha asha 39 Nov 1 15:00 photos/hills.jpgA star matches any run of characters, and a question mark exactly one. The shell expands the pattern before ls runs, so ls *.txt really receives the list of matching names.
Everything below
-R lists this folder and every folder inside it.
asha@pc:~/demo$ ls -R
.:
log.txt
marks.csv
notes.txt
old
photos
report.txt
./old:
draft.txt
./photos:
beach.jpg
hills.jpgFolders marked
-F adds a slash after folder names, which helps when colours are not available. -d lists a folder itself instead of its contents.
asha@pc:~/demo$ ls -F
log.txt
marks.csv
notes.txt
old/
photos/
report.txt
asha@pc:~/demo$ ls -ld photos
drwxr-xr-x 1 asha asha 0 Nov 1 15:00 photosCombining options
Single-letter options can be joined after one dash. ls -lah is the favourite of many people: long, all, human-readable.
| Option | Effect |
|---|---|
-l | long listing |
-a | include hidden files |
-h | human-readable sizes |
-t | sort by time, newest first |
-S | sort by size, largest first |
-r | reverse the order |
-R | include subfolders |
-F | mark folders with a slash |
-1 | one name per line |
Counting files
Pipe the list into wc -l to count lines.
asha@pc:~/demo$ ls | wc -l
6When a file is not there
asha@pc:~/demo$ ls nothing.txt
ls: cannot access 'nothing.txt': No such file or directoryThe message means exactly what it says. Check the spelling, remember that capital letters matter on Linux, and make sure you are in the folder you think you are in with pwd.
Names with spaces
Put the name in quotation marks, or put a backslash before each space: ls "My Documents" or ls My\ Documents. Pressing Tab after the first letters completes a name correctly, spaces included.
On a Mac
The Mac's ls is a slightly different version from the one on Linux. The options on this page work on both. Colours are switched on with ls -G on a Mac and ls --color on Linux.
The Windows equivalent is dir.
Examples shown with output were run on 12 November 2026 in a practice folder: Windows commands in cmd.exe on Windows 11, Linux commands with the GNU tools of Git Bash. The folder path and user name were replaced with made-up ones. Commands marked "not run here" are shown as you would type them.
This is an independent learning site. It is not connected with Microsoft, Apple or any Linux distribution. Windows, macOS and other names belong to their owners. Try commands first in a practice folder, never on files you cannot afford to lose.