<code>ls</code> is a shell command for listing files including special files such as directories. Originally developed for Unix and later codified by POSIX and Single UNIX Specification, it is supported in many operating systems today, including Unix-like variants, Windows (via PowerShell and UnxUtils), EFI, and MSX-DOS (via MSX-DOS2 Tools).
The numerical computing environments MATLAB and GNU Octave include an <code>ls</code> command with similar functionality.
An <code>ls</code> command appeared in the first version of AT&T UNIX. The name inherited from Multics and is short for "list". is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification.
In MS-DOS, OS/2, and Windows, the equivalent command is <code>dir</code>. Apple DOS for the Apple II uses .
When invoked with no path argument, <code>ls</code> lists the files of the working directory. Otherwise, it includes each specified file and each file of a specified directory.
Common options include:
The following example shows the long form output:
Each output line includes a file type letter ('-' for file, 'd' for directory), 9 letters representing permissions, the number of hard links, owning user, owning group, size, modification date, name. In the working directory, the owner <code>fjones</code> has a directory named <code>drafts</code>, a regular file named <code>edition-32</code>, and an executable named <code>edit.sh</code> which is "old", i.e. modified more than 6 months ago as indicated by the display of the year.
Some implementations support color output to indicate metadata. GNU <code>ls</code> provides the <code>--color</code> option which enables using a database to control colors maintained using dircolors. FreeBSD <code>ls</code> provides the <code>-G</code> option which enables using the termcap database The following example shows possible color output:
-rw-r--r-- 1 tsmitt nregion 26650 Dec 20 11:16 <span style="color:dodgerblue ">audio.ogg</span> brw-r--r-- 1 tsmitt nregion 64 Jan 27 05:52 <span style="color:chocolate ">bd-block-device</span> crw-r--r-- 1 tsmitt nregion 255 Jan 26 13:57 <span style="color:chocolate ">cd-character-device</span> -rw-r--r-- 1 tsmitt nregion 290 Jan 26 14:08 <span style="color:magenta ">image.png</span> drwxrwxr-x 2 tsmitt nregion 48 Jan 26 11:28 <span style="color:blue ">di-directory</span> -rwxrwxr-x 1 tsmitt nregion 29 Jan 26 14:03 <span style="color:green ">ex-executable</span> -rw-r--r-- 1 tsmitt nregion 0 Dec 20 09:39 <span style="color:dimgray ">fi-regular-file</span> lrwxrwxrwx 1 tsmitt nregion 3 Jan 26 11:44 <span style="color:dodgerblue ">ln-soft-link</span> -> <span style="color:blue">dir</span> lrwxrwxrwx 1 tsmitt nregion 15 Dec 20 10:57 <span style="color:lightcoral ">or-orphan-link</span> -> <span style="color:white;background:lightcoral">mi-missing-link</span> drwxr-xrwx 2 tsmitt nregion 4096 Dec 20 10:58 <span style="color:blue;background:lime ">ow-other-writeable-dir</span> prw-r--r-- 1 tsmitt nregion 0 Jan 26 11:50 <span style="color:darkgoldenrod ">pi-pipe</span> -rwxr-sr-x 1 tsmitt nregion 0 Dec 20 11:05 <span style="color:black;background:yellow">sg-setgid</span> srw-rw-rw- 1 tsmitt nregion 0 Jan 26 12:00 <span style="color:magenta ">so-socket</span> drwxr-xr-t 2 tsmitt nregion 4096 Dec 20 10:58 <span style="color:white;background:blue ">st-sticky-dir</span> -rwsr-xr-x 1 tsmitt nregion 0 Dec 20 11:09 <span style="color:white;background:red ">su-setuid</span> -rw-r--r-- 1 tsmitt nregion 10240 Dec 20 11:12 <span style="color:red ">compressed.gz</span> drwxrwxrwt 2 tsmitt nregion 4096 Dec 20 11:10 <span style="color:black;background:lime ">tw-sticky-other-writeable-dir</span>