ls: list files and directories
ls lists the contents of a directory. It is usually the first command people type on a new system, and its long format shows permissions, owners, sizes and dates at a glance.
ls [options] [file or directory ...]
Common options
| Option | Meaning |
|---|---|
-l | Long format: permissions, links, owner, group, size, date, name |
-a | Include hidden files (names starting with .) |
-A | Like -a but without . and .. |
-h | Sizes in K, M, G (with -l) |
-t | Sort by modification time, newest first |
-S | Sort by size, largest first |
-r | Reverse the sort order |
-R | List subdirectories recursively |
-d | List a directory itself, not its contents |
-i | Show inode numbers |
-1 | One name per line |
Examples
ls # names in the current directory
ls -l /etc # long listing of /etc
ls -la # include hidden files such as .bashrc
ls -lh # human-readable sizes
ls -ltr # oldest first, newest at the bottom: handy for log directories
ls -lS | head # largest files first
ls -ld /tmp # details of the directory itself
ls -l *.conf # only files ending in .conf
ls -1 | wc -l # count entries
Reading the long format
-rw-r--r-- 1 anna staff 4820 Nov 2 09:14 report.txt
drwxr-x--- 3 anna staff 4096 Oct 30 17:02 projects
lrwxrwxrwx 1 root root 11 Sep 5 2025 vi -> /usr/bin/vim
- The first character is the type:
-file,ddirectory,lsymbolic link,c/bdevice,ssocket,ppipe. - The next nine are the permissions for owner, group and others (see
chmod). A trailing+means an ACL;.means an SELinux context. - Then: number of links, owner, group, size in bytes, modification time, name.
- Dates older than six months show the year instead of the time.
Useful extras
ls -l --time-style=long-iso # full dates: 2026-11-02 09:14 (GNU)
ls -lu # show access time instead of modification time
ls --color=auto # colours (GNU, FreeBSD and recent macOS; older macOS: ls -G)
ls -lZ # SELinux contexts (Linux)
Portability notes
The basic options work everywhere. Long options such as --time-style are GNU extensions. FreeBSD and macOS accept --color or -G for colour and -T for full timestamps; OpenBSD's ls has no colour option. Do not parse the output of ls in scripts; file names can contain spaces and newlines. Use wildcards or find instead.