Template:Short description Template:About Template:Redirect Template:Lowercase {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other ls is a shell command for listing files Template:Endash 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),<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> EFI,<ref name="EFI-Shells-and-Scripting">{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> and MSX-DOS (via MSX-DOS2 Tools).<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

The numerical computing environments MATLAB and GNU Octave include an ls command with similar functionality.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

In other environments, such as DOS, OS/2, and Command Prompt, similar functionality is provided by the dir command.

An ls command appeared in the first version of AT&T UNIX, the name inherited from Multics and short for "list".<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> <syntaxhighlight lang="text" class="" style="" inline="1">ls</syntaxhighlight> 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.<ref>Template:Man</ref>

BehaviorEdit

When invoked with no path argument, ls lists the files of the working directory. Otherwise, it includes each specified file and each file of a specified directory.

Common options include:

  • <syntaxhighlight lang="text" class="" style="" inline="1">-a</syntaxhighlight> Includes all files; even those starting with . which on Unix-based systems are otherwise not included
  • <syntaxhighlight lang="text" class="" style="" inline="1">-A</syntaxhighlight> Same as <syntaxhighlight lang="text" class="" style="" inline="1">-a</syntaxhighlight>, but excludes the special entries . (working directory) and .. (parent of working directory)
  • -l Selects the long output format which extends the default output of the file name with additional information including type (- for regular file, d for directory, l for symbolic link, n for network file, s for socket, p for named pipe (FIFO), c for character special file, bfor block special file), permissions, hard link count, owning user and group, size, last-modified timestamp
  • -h Output sizes as so-called human readable by using units of KB, MB, GB instead of bytes. This option is not part of the POSIX standard, although implemented in several systems, e.g., GNU coreutils in 1997,<ref>{{#invoke:citation/CS1|citation

|CitationClass=web }}</ref> FreeBSD 4.5 in 2002,<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> and Solaris 9 in 2002.<ref>Template:Citation</ref>

  • -R Include files of a directory tree, recursively
  • -t Sort the list by modification time (default sort is alphabetically)
  • -u Sort the list by last access time
  • -c Sort the list by last attribute (status) change time
  • -r Reverse the order, for example most recent time last
  • --full-time Show times down to the millisecond instead of just the minute
  • -1 One entry per line
  • -m Stream format; list items across the page, separated by commas.
  • -g Include group but not owner
  • -o Include owner but not group (when combined with -g both group and owner are suppressed)
  • -d Show information about a directory or symbolic link, rather than the contents of a directory or the link's target
  • -F Append a "/" to directory names and a "*" to executable files

ExampleEdit

The following example shows the long form output: <syntaxhighlight lang="console"> $ ls -l drwxr--r-- 1 fjones editors 4096 Mar 2 12:52 drafts -rw-r--r-- 3 fjones editors 30405 Mar 2 12:52 edition-32 -r-xr-xr-x 1 fjones bookkeepers 8460 Jan 16 2022 edit.sh </syntaxhighlight>

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 fjones has a directory named drafts, a regular file named edition-32, and an executable named edit.sh which is "old", i.e. modified more than 6 months ago as indicated by the display of the year.

<syntaxhighlight lang="console"> ┌─────────── file (not a directory) |┌─────────── read-write (no execution) permissions for the owner |│ ┌───────── read-only permissions for the group |│ │ ┌─────── read-only permissions for others |│ │ │ ┌── 3 hard links |│ │ │ │ ┌── owning user |│ │ │ │ │ ┌── owning group |│ │ │ │ │ │ ┌── file size in bytes |│ │ │ │ │ │ │ ┌── last modified on |│ │ │ │ │ │ │ │ ┌── filename -rw-r--r-- 3 fjones editors 30405 Mar 2 12:52 edition-32 </syntaxhighlight>

Some implementations support color output to indicate metadata. GNU ls provides the --color option<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> which enables using a database to control colors maintained using dircolors. FreeBSD ls provides the -G option which enables using the termcap database<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> The following example shows possible color output:

-rw-r--r--    1 tsmitt nregion   26650 Dec 20 11:16 audio.ogg
brw-r--r--    1 tsmitt nregion      64 Jan 27 05:52 bd-block-device
crw-r--r--    1 tsmitt nregion     255 Jan 26 13:57 cd-character-device
-rw-r--r--    1 tsmitt nregion     290 Jan 26 14:08 image.png
drwxrwxr-x    2 tsmitt nregion      48 Jan 26 11:28 di-directory
-rwxrwxr-x    1 tsmitt nregion      29 Jan 26 14:03 ex-executable
-rw-r--r--    1 tsmitt nregion       0 Dec 20 09:39 fi-regular-file
lrwxrwxrwx    1 tsmitt nregion       3 Jan 26 11:44 ln-soft-link -> dir
lrwxrwxrwx    1 tsmitt nregion      15 Dec 20 10:57 or-orphan-link -> mi-missing-link
drwxr-xrwx    2 tsmitt nregion    4096 Dec 20 10:58 ow-other-writeable-dir
prw-r--r--    1 tsmitt nregion       0 Jan 26 11:50 pi-pipe
-rwxr-sr-x    1 tsmitt nregion       0 Dec 20 11:05 sg-setgid
srw-rw-rw-    1 tsmitt nregion       0 Jan 26 12:00 so-socket
drwxr-xr-t    2 tsmitt nregion    4096 Dec 20 10:58 st-sticky-dir
-rwsr-xr-x    1 tsmitt nregion       0 Dec 20 11:09 su-setuid
-rw-r--r--    1 tsmitt nregion   10240 Dec 20 11:12 compressed.gz
drwxrwxrwt    2 tsmitt nregion    4096 Dec 20 11:10 tw-sticky-other-writeable-dir

See alsoEdit

ReferencesEdit

Template:Reflist

External linksEdit

Template:Sister project

Template:Unix commands Template:Plan 9 commands Template:Core Utilities commands