Skip to content

ls Cheat Sheet: Every Flag You'll Actually Use

A practical ls cheat sheet: listing, sorting, time and size flags, reading ls -l output, quoting, colors, aliases, GNU vs macOS differences, and when to use find.

●By 9 min read

ls is the first command most people learn and the one whose man page almost nobody finishes. GNU coreutils ls has over fifty options; in practice about twenty of them cover everything you do day to day β€” and a few of the defaults, like quoting and the six-month date format, surprise people for years.

This cheat sheet is organised by task: what to show, how to sort, which timestamp, and how to read the long format. Flags are for GNU ls as shipped on Debian, Ubuntu, RHEL and Fedora; macOS and BSD differences get their own table. For the wider toolbox, see the Linux tools cheat sheet.

What to Show

FlagLong formWhat it does
-lLong format: type, permissions, links, owner, group, size, time, name
-a--allInclude hidden entries, including . and ..
-A--almost-allHidden entries, but without . and .. β€” usually what you want
-h--human-readableSizes as 4.0K, 12M, 1.3G (with -l or -s)
-d--directoryList the directory itself, not its contents
-R--recursiveRecurse into subdirectories
-1One entry per line
-F--classifyAppend a type marker: / dir, * executable, @ symlink, | FIFO, = socket
-pAppend / to directories only
-i--inodeShow inode numbers β€” hard links share one
-n--numeric-uid-gidLike -l, with numeric UID and GID instead of names
-s--sizeAllocated size in blocks (disk usage, not file length)
-Z--contextSELinux security context (RHEL, Fedora)
-L--dereferenceShow the target of symlinks instead of the link itself
-I PATTERN--ignore=PATTERNHide entries matching a shell glob

$ ls -lhA /etc/ssh

$ ls -ld /var/log # permissions of the directory itself

$ ls -d */ # only directories in the current directory

$ ls -A | wc -l # count entries (ls prints one per line into a pipe)

$ ls -l -I '*.gz' /var/log # skip compressed rotations

$ ls -lZ /var/www/html # SELinux labels

Sorting

The default sort is alphabetical according to your locale. Every sort flag can be flipped with -r.

FlagSorts byTypical use
-tModification time, newest firstls -lt | head
-trModification time, oldest firstNewest file ends up next to your prompt
-SSize, largest firstls -lhS
-XExtensionGroup .conf, .log, .gz together
-vNatural version orderfile2 before file10; kernel versions in order
-UNo sorting β€” directory orderFastest listing of huge directories
--sort=WORDnone, size, time, version, extensionReadable form in scripts
--group-directories-firstDirectories before filesPairs with any other sort

# Ten largest files in a directory, human-readable

$ ls -lhS /var/log | head -n 11

# What changed most recently?

$ ls -lt /etc | head -n 6

# Version-aware sort

$ ls releases/

v1.10 v1.2 v1.9

$ ls -v releases/

v1.2 v1.9 v1.10

-S does not recurse β€” it sorts the entries of one directory, and a directory's own size is just its metadata block. For "what is using space" use du or the disk usage analyzer.

Huge directories β€” in a directory with millions of files, ls reads everything before it can sort. ls -U or -f skips sorting and starts printing right away.

Timestamps and Time Formats

A file has several timestamps, and ls -l shows only one of them β€” modification time β€” unless told otherwise. The same flag changes both which time is displayed and which time -t sorts by.

FlagTimestampChanges when
(default)mtime β€” modificationFile contents are written
-cctime β€” status changeContents, permissions, owner or link count change
-uatime β€” last accessFile is read (subject to relatime and noatime)
--time=birthCreation timeFile is created β€” needs coreutils 8.32+ and filesystem support
OptionExample output
(default)Oct 2 09:12 (or Mar 14 2026 if older than six months)
--time-style=long-iso2026-10-02 09:12
--time-style=full-iso2026-10-02 09:12:44.183452917 +0000
--full-timeSame as -l --time-style=full-iso
--time-style=+%Y-%m-%d2026-10-02 (any date(1) format)

# Which files had permissions or ownership changed recently?

$ ls -lct /etc | head

# Exact, sortable timestamps for a log or a ticket

$ ls -l --time-style=long-iso /var/backups

The six-month rule β€” files modified more than six months ago, or with a timestamp in the future, show the year instead of the time of day. That is why a column of times suddenly turns into years.

For one file, use stat β€” stat file prints access, modify, change and (where supported) birth times at full precision in one go.

sponsored

Reading ls -l Output

$ ls -la /srv/app

total 24

drwxr-xr-x 4 deploy deploy 4096 Oct 2 09:12 .

drwxr-xr-x 4 root root 4096 Sep 14 11:03 ..

-rw------- 1 deploy deploy 220 Sep 14 11:03 .env

-rw-r-----+ 1 deploy www 1843 Oct 1 17:40 app.conf

lrwxrwxrwx 1 deploy deploy 12 Oct 2 09:10 current -> releases/v42

-rwsr-x--- 1 root deploy 8728 Aug 3 08:21 helper

drwxr-xr-x 12 deploy deploy 4096 Oct 2 09:10 releases

drwxrwsr-x 2 deploy www 4096 Oct 2 09:12 shared

ColumnExampleMeaning
1st characterd, -, lFile type (see below)
Next 9rw-r-----Permissions for owner, group, others
Trailing marker+ or .+ means an ACL is set; . means an SELinux context and no ACL
Link count12Hard links; for a directory, 2 plus its number of subdirectories
Owner, groupdeploy wwwNames, or numbers if the account no longer exists
Size1843Bytes (use -h); for symlinks, the length of the target path
TimeOct 1 17:40mtime by default
Namecurrent -> releases/v42Symlinks show their target
TypeMeaningSpecial bitMeaning
-Regular files in owner xsetuid, and executable
dDirectoryS in owner xsetuid, not executable β€” usually a mistake
lSymbolic links in group xsetgid; on a directory, new files inherit the group
c / bCharacter / block devicet in other xSticky: only owners can delete (like /tmp)
p / sNamed pipe / socketT in other xSticky, not executable by others

The total line β€” the first line, total 24, is the disk space used by the listed files in 1 KiB blocks (or human-readable with -h), not a file count.

Decode permissions quickly β€” paste a string like rwxr-s--- into the chmod calculator, or read the full model in our Linux file permissions guide.

See the ACL behind the + β€” getfacl app.conf shows the extra entries. ls only tells you that one exists.

Quoting, Colors and Aliases

Since coreutils 8.25, ls quotes names that contain spaces or special characters when writing to a terminal, so a file called my file shows as 'my file'. It is not part of the name; it is there so you can paste it back into a shell.

OptionEffect
-N--literal: print names as they are, no quoting
-Q--quote-name: wrap every name in double quotes
-b--escape: C-style escapes for non-printable characters
-qShow non-printable characters as ?
--quoting-style=WORDliteral, shell, shell-always, shell-escape, c, escape, locale
--color=WHENauto (only on a terminal), always, never

# Where does ll come from on this machine?

$ type ll

ll is aliased to `ls -alF' # Ubuntu/Debian ~/.bashrc

ll is aliased to `ls -l --color=auto' # RHEL/Fedora /etc/profile.d/colorls.sh

# Bypass an alias for one run

$ \ls

$ command ls

# Customise colors

$ dircolors -p > ~/.dircolors

$ eval "$(dircolors -b ~/.dircolors)"

--color=always in pipes β€” it embeds escape codes in the output, which breaks grep and awk downstream. auto is the right setting for aliases.

Useful aliases β€” alias lt='ls -lhtr' for newest-last and alias lsz='ls -lhS' for largest-first, cover most ad-hoc investigations.

GNU vs macOS, and When Not to Use ls

TaskGNU / LinuxmacOS / BSD
Color output--color=auto-G
Meaning of -GOmit group in long listingEnable color
Directories first--group-directories-firstNot available
Full timestamp--full-time-lT
Extended attributesgetfattr / -Z for SELinux-l@
ACLs+ marker, then getfacl-le
Install GNU lsAlready installedbrew install coreutils, then gls

Do not parse ls output in scripts. File names can contain spaces, newlines and glob characters, and the format changes with locale, terminal and age of the file. Use globs, find or stat instead:

# Wrong: breaks on spaces and newlines in names

for f in $(ls *.log); do gzip "$f"; done

# Right: let the shell expand the glob

for f in ./*.log; do [ -e "$f" ] && gzip "$f"; done

# Size and name, machine-readable

$ stat -c '%s %n' /var/log/*.log

$ find /var/log -maxdepth 1 -name '*.log' -printf '%s\t%TY-%Tm-%Td\t%p\n'

# Newest file in a directory, safely

$ find /var/backups -maxdepth 1 -type f -printf '%T@ %p\n' | sort -n | tail -n 1

Recursive listings β€” ls -R is fine for a quick look; for anything you filter or act on, find is more precise. Our Linux commands reference covers both.

The [ -e ] check β€” if no file matches, an unquoted glob stays literal as ./*.log. The test skips that case without needing shell options like nullglob.

Frequently Asked Questions

How do I list files sorted by size in Linux?

Use ls -lhS to list the largest files first with human-readable sizes, or ls -lhSr for smallest first. This sorts the entries of a single directory only; to find what uses the most space across subdirectories, use du -sh * or a disk usage tool.

How do I show hidden files with ls?

ls -a shows all entries including . and .., and ls -A shows hidden files without those two. Combine with -l for details: ls -lA. Hidden files are simply names that start with a dot.

Why does ls show a year instead of a time for some files?

GNU ls shows the time of day only for files modified within the last six months. Older files, and files with timestamps in the future, show the year instead. Use --time-style=long-iso or --full-time to get a consistent format.

What does the + or . after the permissions in ls -l mean?

A + means the file has an access control list beyond the normal permission bits; inspect it with getfacl. A . means the file has an SELinux security context and no ACL; view it with ls -Z.

Why does ls put quotes around some file names?

Since coreutils 8.25, ls quotes names containing spaces or special characters when the output is a terminal, so they can be pasted back into a shell safely. The quotes are not part of the name. Use ls -N or --quoting-style=literal to turn them off.

sponsored

Related Tools

See also