Updated: 8 October 2026 · Applies to: Debian 13, Ubuntu 24.04 and 26.04, AlmaLinux 10 (GNU coreutils ls 9.4 to 9.7; uutils ls 0.10.0 on Ubuntu 26.04)
To list files in Linux, type ls. On its own it shows the names in the current directory; add a path to list another directory. For a full picture of a directory, use ls -lah: long format (permissions, owner, size, date), all files including hidden ones, and human-readable sizes.
ls ls /var/log ls -lah
List the files in a directory
In an SSH session, ls prints the names in columns, sorted alphabetically:
$ ls backup-site.tar.gz index.html releases report2.txt current logs report1.txt report3.txt images notes.txt report10.txt style.css
When the output goes into a pipe or a file, ls prints one name per line instead; ls -1 does the same on screen. To see which names are directories, add -F: it appends / to directories, @ to symbolic links and * to executable files:
$ ls -F backup-site.tar.gz images/ notes.txt report10.txt style.css current@ index.html releases/ report2.txt deploy.sh* logs/ report1.txt report3.txt
Read the long listing (ls -l)
$ ls -l total 5160 -rw-r--r-- 1 root root 5242880 Oct 7 02:30 backup-site.tar.gz lrwxrwxrwx 1 root root 12 Oct 5 10:00 current -> releases/1.5 drwxr-xr-x 2 root root 4096 Oct 5 10:00 images -rw-r--r-- 1 root root 49 Oct 7 21:14 index.html drwxr-xr-x 2 root root 4096 Oct 5 10:00 logs -rw-r--r-- 1 root root 30 Mar 2 2026 notes.txt drwxr-xr-x 4 root root 4096 Oct 5 10:00 releases -rw-r--r-- 1 root root 7 Oct 1 12:00 report1.txt -rw-r--r-- 1 root root 2 Oct 1 12:00 report10.txt -rw-r--r-- 1 root root 7 Oct 1 12:00 report2.txt -rw-r--r-- 1 root root 7 Oct 1 12:00 report3.txt -rw-r--r-- 1 root root 40 Oct 6 18:02 style.css
Each line has seven parts, from left to right:
- Type and permissions, for example
-rw-r--r--. The first character is the type:-a regular file,da directory,la symbolic link. The next nine characters are the read, write and execute rights of the owner, the group and everyone else. To change them, see commands for changing file access rights. - Link count: the number of hard links. For a directory it is 2 plus the number of subdirectories, which is why
releasesshows 4. - Owner and group.
ls -nshows the numeric user and group IDs instead. - Size in bytes. For a directory, 4096 is the size of the directory's own list of names, not of the files inside it. To measure a folder, use
du -sh(see file and partition sizes). - Last modification time. The GNU manual calls a timestamp recent if it is less than six months old and not in the future; recent files show the time, all others show the year instead, like
notes.txtabove. - Name. A symbolic link also shows
->and its target.
The total line is the disk space used by the files listed, in 1024-byte blocks by default. ls -s shows that figure for each file.
Show hidden files
Names that start with a dot, such as .env and .htaccess, are hidden from a plain ls. ls -a shows them together with . (this directory) and .. (the parent). ls -A shows the hidden files without those two:
$ ls -A .env current logs report1.txt report3.txt .htaccess images notes.txt report10.txt style.css backup-site.tar.gz index.html releases report2.txt
Human-readable sizes
-h prints sizes as K, M and G in powers of 1024. --si uses powers of 1000, so the same file looks slightly bigger:
$ ls -lh backup-site.tar.gz -rw-r--r-- 1 root root 5.0M Oct 7 02:30 backup-site.tar.gz $ ls -lh --si backup-site.tar.gz -rw-r--r-- 1 root root 5.3M Oct 7 02:30 backup-site.tar.gz
Sort the list
ls -lt: newest first.ls -ltrputs the newest at the bottom, which is handy in a log directory. More examples in sorting ls output by date and time.ls -lS: largest first.ls -lhS imagesgavehero.jpg(2.4M) abovelogo.png(18K).ls -X: by extension.ls --group-directories-first: directories before files.ls -v: natural number order. Normal sorting is character by character, soreport10.txtcomes beforereport2.txt:
$ ls report* report1.txt report10.txt report2.txt report3.txt $ ls -v report* report1.txt report2.txt report3.txt report10.txt
Add -r to reverse any sort order.
List a directory itself, only directories, or everything below
$ ls -ld images drwxr-xr-x 2 root root 4096 Oct 5 10:00 images $ ls -d */ current/ images/ logs/ releases/
Without -d, ls -l images lists the files inside images. ls -R lists all subdirectories recursively; on a big tree, find is easier to filter (see looking for files).
Other useful options
--time-style=long-iso: full dates such as2026-10-07 21:14on every line, easier to compare thanOct 7 21:14.-uand-c: show (and with-t, sort by) the last access time or the last status change time instead of the modification time.-i: the inode number of each file, useful when checking hard links.-Q: names in double quotes, which makes spaces at the start or end of a name visible.
Shortcuts: ll, la and l
- Ubuntu 24.04 and 26.04:
~/.bashrcdefinesllasls -alF,laasls -Aandlasls -CF. - Debian 13:
llandlappear in~/.bashrconly as commented-out examples, solldoes not work until you remove the#in front of it. - AlmaLinux 10 (with the full
coreutilspackage):/etc/profile.d/colorls.shdefinesllasls -l --color=autoandl.asls -d .* --color=auto.
Run type ll to see what an alias really runs.
Common mistakes
ls -l *also lists inside subdirectories. The shell turns*into every name, directories included, andlsthen lists each directory's contents under its own heading. Usels -ld *to list the directories as entries. How*and other wildcards work is explained in shell wildcards and globbing.- Counting files with
ls | wc -lmisses hidden files. In the example directory it returned 12, whilels -A | wc -lreturned 14. - Parsing
lsoutput in scripts. Names with spaces or line breaks break it. Loop over a wildcard (for f in *.log) or usefindinstead. - Wrong case or path. Linux names are case-sensitive. A missing name gives
ls: cannot access 'nosuchfile': No such file or directoryand exit status 2.
Ubuntu 26.04: ls is the uutils version
Ubuntu 26.04 uses the Rust rewrite of coreutils (uutils) by default, so ls --version prints ls (uutils coreutils) 0.10.0. Every command in this article gave the same result as GNU ls 9.7 on Debian 13, with two small differences we found: with -t, files with exactly the same timestamp were not ordered by name, and ls -l --block-size=K printed the size as 5120 where GNU printed 5120K (the unit letter is missing). GNU ls is still installed as gnuls if a script depends on its exact output.
Related: display file contents with cat, less, head and tail and sort, filter and count text with grep, sort, uniq, wc, cut and tr. Practise on your own server with full root access on a KVM VPS.
