ls
List directory contents — permissions, owners, sizes, dates, sorting
ls shows the contents of directories and information about files. Without arguments — the current directory; hidden files (names starting with a dot) aren't shown. The sandbox has GNU coreutils 9.4.
Syntax
ls [options] [file_or_directory…]
If an argument is a directory, ls prints its contents; to see the directory itself, add -d. With several arguments: files first, then each directory as a separate block with a name: header.
Exit code: 0 — all is well, 1 — minor problems (a subdirectory couldn't be opened), 2 — serious ones (an argument doesn't exist).
Long format -l
-rw-r--r-- 1 root root 1530 Sep 30 13:10 /etc/passwd
drwxr-xr-x 2 root root 4096 Oct 13 15:20 sub
lrwxrwxrwx 1 root root 5 Oct 13 15:20 lnk -> a.txt
crw-rw-rw- 1 root root 1, 3 Oct 13 15:20 /dev/null
| Column | Meaning |
|---|---|
| 1st character | type: - file, d directory, l symbolic link, c character device, b block device, p named pipe (FIFO), s socket |
rw-r--r-- | permissions of the owner, group, others. s/S in place of x — SUID/SGID (with x / without), t/T — the sticky bit (as on /tmp: drwxrwxrwt) |
+ after the permissions | the file has an ACL (see getfacl) |
| a number | the hard link count; for a directory usually 2 + the number of subdirectories (in container overlayfs it can be just 1) |
root root | owner and group (-n — numeric UID/GID) |
| size | in bytes (-h — in K/M/G). For a directory — the size of the directory entry itself (usually 4096), not its contents. For devices — a "major, minor" number pair |
| date | content modification time (mtime). Files younger than six months — Mon DD HH:MM, older — Mon DD YYYY |
| name | for a link — name -> target |
The total N line above the list is how much space the listed files take, in 1 KiB blocks (with -h — in K/M).
Options
What to show
| Option | What it does |
|---|---|
-a | show everything, including hidden files and ./.. |
-A | show hidden files, but not . and .. |
-d | show the directory itself rather than its contents: ls -ld /etc |
-R | walk subdirectories recursively |
-I 'pattern' | hide matching names (can be repeated); --hide='pattern' — the same, but -a/-A override it |
-L | for links show information about the target, not the link itself |
-H | follow links only from the command line |
Output format
| Option | What it does |
|---|---|
-l | long format (the table above) |
-h | sizes as 1.5K, 234M, 2G (powers of 1024); --si — powers of 1000 |
--block-size=M | show sizes in the given units (K, M, G), rounding up |
-n | like -l, but numeric UID and GID instead of names |
-g / -o | like -l, but without the owner / without the group |
-i | inode number before the name |
-s | disk space used in blocks (with -h — in K/M) |
-1 | one name per line |
-m | comma-separated on one line |
-F | a type indicator after the name: / directory, * executable, @ link, | FIFO, = socket |
-p | only / after directories |
--full-time | the full date with seconds, nanoseconds and time zone |
--time-style=long-iso | date 2026-10-13 15:20; full-iso, iso, +FORMAT (as in date): --time-style=+%F |
-Q | names in double quotes; -N — no quotes at all |
--color=auto | color by type, only if output goes to a terminal; always — always, never — never |
--group-directories-first | directories at the top of the list |
Sorting
By default — by name, according to the locale.
| Option | How it sorts |
|---|---|
-t | by modification time (mtime), newest first |
-S | by size, largest first |
-X | by extension |
-v | "naturally": b2 before b10 |
-U | don't sort (directory order) — faster on huge directories |
-r | reverse any order: -ltr — oldest at the top, newest at the bottom |
--sort=WORD | size, time, version, extension, width, none |
-u | with -lt: sort by and show access time (atime) |
-c | with -lt: by metadata change time (ctime) |
--time=birth | use the file creation time (if the filesystem stores it) |
Examples
# detailed, with hidden files and human-readable sizes
ls -lah /etc/ssh
# permissions of the directory itself, not its contents
ls -ld /var/log
# newest files at the bottom of the list
ls -ltr /var/log
# the five largest files in a directory
ls -lS /usr/bin | head -6
# only subdirectories of the current directory
ls -d */
# inode numbers: hard links share them
ls -li
# date in ISO format — convenient for comparisons and scripts
ls -l --time-style=long-iso /etc/hostname
# numeric UID/GID — visible when the owner isn't in /etc/passwd
ls -ln /srv
Pitfalls
- Don't parse
lsoutput in scripts. Names with spaces and newlines breakfor f in $(ls), and the date format depends on the file's age and the locale. Use the globfor f in *orfind … -print0. - Output to a terminal and to a pipeline differs. In a terminal — columns and quoted names (
'with space'); in a pipeline (ls | …) — one name per line without quotes. ls -l directoryshows the contents, not the directory's permissions. For the directory itself —-d.- A link to a directory:
ls linkshows the target's contents, whilels -l linkshows the link itself (ld -> d). Add a trailing/(ls -l link/) or-Lto look inside. - The directory size in
-l(4096) isn't the size of its contents. To see how much the whole directory takes up, use du. -t,-Sand-rwith file arguments sort only the files; directories from the arguments are still printed as separate blocks after them — add-d.--block-size=Krounds up: a 1530-byte file shows as2K.- Colors. A bash script has no
ls --color=autoalias — without--colorthe output isn't colored. With--color=always, escape codes end up in a file.