ls

List information about files.

Syntax
      ls [Options]... [File]...

Key
  -a, --all                  List all entries including those starting with a dot .

  -A, --almost-all           List all entries including those starting with a dot .
                             Except for . and .. (implied).

  -b, --escape               Print octal escapes for nongraphic characters.

      --block-size=SIZE      Use SIZE-byte blocks.

  -B, --ignore-backups       Do not list implied entries ending with ~

  -c                         Sort by change time; with -l: show ctime.

  -C                         List entries by columns.

      --color[=WHEN]         Control whether color is used to distinguish file types.
                             WHEN can be 'never', 'always', or 'auto'

  -d, --directory            List directory entries instead of contents.

  -D, --dired                Generate output designed for Emacs' dired mode.

  -f                         Do not sort, enable -aU, disable -lst

  -F, --classify             Append indicator (one of */=@|) to entries.

      --format=WORD          Across -x, commas -m, horizontal -x, long -l,
                             single-column -1, verbose -l, vertical -C

      --full-time            List both full date and full time

  -g                         (ignored)

  -G, --no-group             Inhibit display of group information.

  -h, --human-readable       Print sizes in human readable format (e.g., 1K 234M 2G)
  -H, --si                   Likewise, but use powers of 1000 not 1024

      --indicator-style=WORD Append indicator with style WORD to entry names:
                             none (default), classify (-F), file-type (-p)

  -i, --inode                Print index number of each file.

  -I, --ignore=PATTERN       Do not list implied entries matching shell PATTERN

  -k, --kilobytes            Like --block-size=1024

  -l                         Use a long listing format.

  -L, --dereference          List entries pointed to by symbolic links.

  -m                         Fill width with a comma separated list of entries.

  -n, --numeric-uid-gid      List numeric UIDs and GIDs instead of names.

  -N, --literal              Print entry names without quoting My File not 'My File'
                             Don’t treat e.g. control characters specially.
                             This can be made the default with:  alias ls='/bin/ls -N' 

  -o                         Use long listing format without group info.

  -p, --file-type            Append indicator (one of /=@|) to entries.

  -q, --hide-control-chars   Print ? instead of non graphic characters.

      --show-control-chars   Show non graphic characters as-is (default)

  -Q, --quote-name           Enclose entry names in double quotes
      --quoting-style=WORD   Use quoting style WORD for entry names:
                             literal, shell, shell-always, c, escape.

  -r, --reverse              Reverse order while sorting.

  -R, --recursive            List subdirectories recursively.

           For example, ls -R *.jpg will invoke ls recursively on anything matching *.jpg in the
           current directory but if nothing matches, it will stop there. When ls does
           find a match, it will only recurse further if the match is a directory.
           To recursively search through ALL subfolders, use find.

  -s, --size                 Print size of each file, in blocks.

  -S                         Sort by file size.

      --sort=WORD            time -t, version -v, status -c 
                             size -S, extension -X, none -U
                             atime -u, access -u, use -u
                             
      --time=WORD            Show time as WORD instead of modification time:
                               atime, access, use, ctime or status; 
                               also use this as a sort key if --sort=time

  -t                         Sort by modification time.

  -T, --tabsize=COLS         Assume tab stops at each COLS instead of 8.

  -u                         Sort by last access time; with -l: show atime.

  -U                         Do not sort; list entries in directory order.

  -v                         Sort by version.

  -w, --width=COLS           Assume screen width instead of current value.

  -x                         List entries by lines instead of by columns.

  -X                         Sort alphabetically by entry extension.

  -1                         List one file per line.

      --help                 Display help and exit.

      --version              Output version information and exit.

By default ls will sort entries alphabetically if none of -cftuSUX nor --sort are given.

The most common ls options are -a (all files) and -l (long or details).
Tab completion is supported and can be configured with .inputrc
When output to file the files are listed one per line.

ls is pronounced as the two letters: "ell ess"

The Long Format

If the -l option is given, the following information is displayed for each file: file mode, number of links, owner name, group name, number of bytes in the file, abbreviated month, day-of-month file was last modified, hour file last modified, minute file last modified, and the pathname.

In addition, for each directory whose contents are displayed, the total number of 512-byte blocks used by the files in the directory is displayed on a line by itself, immediately before the information for the files in the directory.

The file mode printed under the -l option will display permissions, which can be set with chmod. This consists of the entry type, owner permissions, and group permissions. The entry type character describes the type of file, as follows:

 - Regular file.
 b Block special file.
 c Character special file.
 d Directory.
 l Symbolic link.
 p FIFO.
 s Socket link.
 w Whiteout.

The next three fields are three characters each: owner permissions, group permissions, and other permissions. Each field has three character positions:

1. If r, the file is readable; if -, it is not readable.

2. If w, the file is writable; if -, it is not writable.

3. The first of the following that applies:

S If in the owner permissions, the file is not executable and set-user-ID mode is set. If in the group permissions, the file is not executable and set-group-ID mode is set.
s If in the owner permissions, the file is executable and set-user-ID mode is set. If in the group permissions, the file is executable and setgroup-ID mode is set.
x The file is executable or the directory is searchable.
- The file is neither readable, writable, executable, nor set-user-ID nor set-group-ID mode, nor sticky. (See below.)

These next two apply only to the third character in the last group (other permissions).

T The sticky bit is set (mode 1000), but not execute or search permission. (See chmod(1) or sticky(8).)
t The sticky bit is set (mode 1000), and is searchable or executable. (See chmod(1) or sticky(8).)

If the file or directory has extended attributes, the permissions field printed by the -l option is followed by an @ character. Otherwise, if the file or directory has extended security information, the permissions field printed by the -l option is followed by a + character.

By default, colour is not used to distinguish types of files. That is equivalent to using --color=none.
Using the --color option without the optional WHEN argument is equivalent to using --color=always.
With --color=auto, color codes are output only if standard output is connected to a terminal (tty).

Examples

List the contents of your home directory:

$ ls ~

List everything in a vertical list:

$ ls -al

total 109
drwxr-xr-x 18 root root 4096 Jun 9 21:12 ./
drwxr-xr-x 18 root root 4096 Jun 9 21:12 ../
drwxr-xr-x 2 root root 4096 Jun 9 21:14 bin/
drwxr-xr-x 3 root root 1024 Jun 9 20:32 boot/
drwxr-xr-x 6 root root 36864 Jul 12 10:26 dev/
drwxr-xr-x 34 root root 4096 Jul 12 10:25 etc/

^
the first column is the file type
d = directory
f = file

List the directories in the current directory:

$ ls -d */

List all subdirectories:

$ ls *

Loop through all the files in a folder, note the use of quotes to cope with filenames that include spaces:

$ ls | while read FILE; do echo "$FILE"; done

List all files, one per line, including subdirectories - using find:

$ find ~/Documents/ -type f

The default behaviour of ls is to only pass color control codes to tty output --color=auto.
To pipe the output to a second command complete with color codes then set --color=always

A list of environment variables that affect ls (colour, column width, blocksize etc) :

$ ls -lAXh --color=auto|less -R

“If the doors of perception were cleansed every thing would appear to man as it is, infinite” ~ William Blake

Related Linux commands

cd - Change Directory.
chmod - Change access permissions.
dir - Briefly list directory contents.
dircolors - Colour setup for ls.
dirname - Convert a full pathname to just a path.
lsblk - List block devices.
lspci - List PCI devices.
quota - Display disk usage and limits.
rm - Remove files.
rmdir - Remove folder(s).
wc - Print byte, word, and line counts.
Equivalent Windows command: DIR - Display a list of files and folders.


 
Copyright © 1999-2026 SS64.com
Some rights reserved