ls
Program: ls
Lists what is in a directory.
Usage
ls [OPTION]... [FILE]...
Description
List the entries of each FILE that is a directory, and the name of each other FILE. Without FILE, list the current directory. Names are sorted by their bytes unless -t or -S is given.
Options in the simulator
46 more options of the real program, not in the simulator yet
Examples
ls
Documents Downloads Pictures notes.txt projects ls Downloads/*.pdf
Downloads/invoice.pdf ls -l Downloads
total 636
-rw-r--r-- 1 lerner lerner 120000 Aug 10 18:05 'beach(1).jpg'
-rw-r--r-- 1 lerner lerner 120000 Aug 10 18:00 beach.jpg
-rw-r--r-- 1 lerner lerner 41000 Aug 31 10:00 invoice-2026-08.pdf
-rw-r--r-- 1 lerner lerner 42000 Sep 30 10:00 invoice-2026-09.pdf
-rw-r--r-- 1 lerner lerner 43000 Oct 15 10:02 'invoice-2026-10(1).pdf'
-rw-r--r-- 1 lerner lerner 43000 Oct 15 10:00 invoice-2026-10.pdf
-rw-r--r-- 1 lerner lerner 3000 Nov 2 2025 movie.mp4.part
-rw-r--r-- 1 lerner lerner 52000 Mar 1 2026 rental-contract.pdf
-rw-r--r-- 1 lerner lerner 95000 Aug 11 20:30 sunset.jpg
-rw-r--r-- 1 lerner lerner 64000 May 20 09:00 tax-return-2025.pdf
-rw-r--r-- 1 lerner lerner 1200 Dec 19 2025 update.zip.part ls -la
total 40
drwxr-xr-x 6 lerner lerner 4096 Oct 17 08:58 .
drwxr-xr-x 3 root root 4096 Oct 17 08:58 ..
-rw-r--r-- 1 lerner lerner 12 Sep 1 12:00 .bashrc
-rw-r--r-- 1 lerner lerner 13 Sep 1 12:00 .profile
-rw------- 1 lerner lerner 56 Oct 2 08:00 .secret
drwxr-xr-x 2 lerner lerner 4096 Oct 14 10:30 Documents
drwxr-xr-x 2 lerner lerner 4096 Oct 1 03:00 archive
drwxr-xr-x 2 lerner lerner 4096 Oct 17 09:41 logs
-rw-r--r-- 1 lerner lerner 76 Oct 17 08:15 notes.txt
drwxr-xr-x 3 lerner lerner 4096 Oct 13 14:00 projects ls logs nope > all.txt
ls: cannot access 'nope': No such file or directory
cat all.txt
logs:
app.log
app.log.1
ls logs nope > all.txt 2>&1
cat all.txt
ls: cannot access 'nope': No such file or directory
logs:
app.log
app.log.1 ls cache | tee inventory.txt
a.tmp
b.tmp
keep.log
old report.tmp
echo "checked 09:45" | tee -a inventory.txt
checked 09:45
cat inventory.txt
a.tmp
b.tmp
keep.log
old report.tmp
checked 09:45 ls Documents
notes.txt old-draft.txt ls Documents
notes.txt old-draft.txt ls -la Documents
total 16
drwxr-xr-x 2 lerner lerner 4096 Oct 16 18:00 .
drwxr-xr-x 6 lerner lerner 4096 Oct 17 08:58 ..
-rw-r--r-- 1 lerner lerner 141 Oct 16 18:00 notes.txt
-rw-r--r-- 1 lerner lerner 51 Oct 14 10:30 report.txt ls -lh Downloads
total 2.4M
-rw-r--r-- 1 lerner lerner 2.2M Oct 8 16:00 manual.pdf
-rw-r--r-- 1 lerner lerner 147K Oct 15 20:00 photo.jpg
-rwxr-xr-x 1 lerner lerner 26 Oct 12 09:00 setup.sh ls -lt Downloads
total 2400
-rw-r--r-- 1 lerner lerner 150000 Oct 15 20:00 photo.jpg
-rwxr-xr-x 1 lerner lerner 26 Oct 12 09:00 setup.sh
-rw-r--r-- 1 lerner lerner 2300000 Oct 8 16:00 manual.pdf ls Downloads
manual.pdf photo.jpg setup.sh
rm -i Downloads/setup.sh
rm: remove regular file 'Downloads/setup.sh'? y
ls Downloads
manual.pdf photo.jpg Where you learn it
Lessons
- Where am I? pwd, ls and cd Terminal start
- Deleting without regrets Terminal start
- Final scenario: tidying up Downloads Terminal start
- Finding your way around a strange server Linux Basics, Module 1: Survival basics
- Steering the streams Linux Basics, Module 4: Pipes and redirection
- Branching off and passing on Linux Basics, Module 4: Pipes and redirection
- Example: tidy up a folder Workshop
- Example: steps in the right order Workshop