Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Ls
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Shell command for listing files}} {{about|the Unix-style command line shell directory listing command|other uses|LS (disambiguation){{!}}LS}} {{redirect|ls(1)|similarly named topics|LS1 (disambiguation)}} {{Lowercase|title=ls}} {{Infobox software | name = ls | screenshot = Ls --color=auto -ls linux.png | caption = Long file listing with <code>ls --color=auto -l</code> in Linux showing various modes, date formats, colors and appended indicators (executables and directories). | author = coreutils: [[Richard Stallman]] and David MacKenzie | developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers | programming language = [[C (programming language)|C]] | operating system = [[Multics]], [[Unix]], [[Unix-like]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]], [[MSX-DOS]] | genre = [[Command (computing)|Command]] | license = [[coreutils]]: [[GPLv3+]]<br />[[BusyBox]]: [[GNU General Public License|GPL-2.0-only]]<br />[[Toybox]]: [[BSD licenses|0BSD]]<br />Plan 9: [[MIT License]] | website = }} '''<code>ls</code>''' is a [[shell (computing)|shell]] [[command (computing)|command]] for listing [[computer file|files]] {{endash}} including [[Unix file type|special files]] such as [[computer directory|directories]]. Originally developed for [[Unix]] and later codified by [[POSIX]] and [[Single UNIX Specification]], it is supported in many [[operating system]]s today, including [[Unix-like]] variants, [[Microsoft Windows|Windows]] (via [[PowerShell]] and [[UnxUtils]]),<ref>{{Cite web|url=http://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}}</ref> [[Unified Extensible Firmware Interface|EFI]],<ref name="EFI-Shells-and-Scripting">{{cite web |title=EFI Shells and Scripting |url=http://software.intel.com/en-us/articles/efi-shells-and-scripting/ |url-status=deviated |archive-url=https://web.archive.org/web/20130927203229/http://software.intel.com/en-us/articles/efi-shells-and-scripting/ |archive-date=September 27, 2013 |access-date=2013-09-25 |publisher=[[Intel]]}}</ref> and [[MSX-DOS]] (via [[ASCII Corporation|MSX-DOS2 Tools]]).<ref>{{Cite web|url=https://archive.org/details/MSXDOS2TOOLS|title=MSX-DOS2 Tools User's Manual - MSX-DOS2 TOOLS γ¦γΌγΆγΌγΊγγγ₯γ’γ«|date=April 1, 1993|via=Internet Archive}}</ref> The [[numerical analysis|numerical computing]] environments [[MATLAB]] and [[GNU Octave]] include an <code>ls</code> command with similar functionality.<ref>{{Cite web|url=https://www.mathworks.com/help/matlab/ref/ls.html|title = List folder contents - MATLAB ls}}</ref><ref>{{Cite web |title=Function Reference: Ls |url=https://octave.sourceforge.io/octave/function/ls.html |website=Octave Forge}}</ref> In other environments, such as [[DOS]], [[OS/2]], and [[Command Prompt]], similar functionality is provided by the <code>[[dir (command)|dir]]</code> command. An <code>ls</code> command appeared in the first version of [[AT&T Corporation|AT&T]] [[Unix|UNIX]], the name inherited from [[Multics]] and short for "list".<ref>{{Cite web |date=14 February 1985 |title=Multics manual page for ls or list command |url=https://web.mit.edu/multics-history/source/Multics/doc/info_segments/list.info}}</ref><ref>{{cite web |url=https://tldp.org/LDP/LG/issue48/fischer.html |title=A Brief History of the 'ls' command |first=Eric |last=Fischer |website=[[The Linux Documentation Project]]}}</ref><ref>{{cite web | url = http://bitsavers.org/pdf/honeywell/large_systems/multics/AG92-03A_multicsCmds_Feb80.pdf | title = Multics programmer's manual - Commands and active functions | page = 397 }}</ref> {{code|ls}} 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>{{man|cu|ls|SUS}}</ref> == Behavior == When invoked with no path [[Command-line argument|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: * {{code|-a}} Includes '''a'''ll files; even those starting with <code>.</code> which on Unix-based systems are otherwise [[Hidden file and hidden directory#Unix and Unix-like environments|not included]] * {{code|-A}} Same as {{code|-a}}, but excludes the special entries <code>.</code> (working directory) and <code>..</code> (parent of working directory) * <code>-l</code> Selects the '''l'''ong output format which extends the default output of the file name with additional information including [[Unix file types|type]] (<code>-</code> for regular file, <code>d</code> for directory, <code>l</code> for [[Symbolic link|symbolic link]], <code>n</code> for [[Network filesystem|network file]], <code>s</code> for [[Network socket|socket]], <code>p</code> for [[named pipe]] (FIFO), <code>c</code> for [[Device file|character special file]], <code>b</code>for [[Device file|block special file]]), permissions, [[hard link]] count, owning user and group, size, last-modified timestamp * <code>-h</code> Output sizes as so-called '''h'''uman 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>{{cite web |url=http://git.savannah.gnu.org/cgit/coreutils.git/commit/src/ls.c?id=b76a4533046163978f7517f9ea6d3307bfa0a98a |title=(decode_switches): -h and -H override output units. |publisher=coreutils.git |date=1997-12-31 }}</ref> FreeBSD 4.5 in 2002,<ref>{{cite web |url=https://svnweb.freebsd.org/base?view=revision&revision=88591 |title=[base] Log of /stable/10/bin/ls/ls.c |date=2001-12-28}}</ref> and Solaris 9 in 2002.<ref>{{citation |url=http://docs.oracle.com/cd/E19683-01/806-5202/6je7shk5c/index.html |title=What's New in the Solaris 9 Operating Environment |publisher=Sun Microsystems |year=2002}}</ref> * <code>-R</code> Include files of a directory tree, '''r'''ecursively * <code>-t</code> Sort the list by modification time (default sort is alphabetically) * <code>-u</code> Sort the list by last access time * <code>-c</code> Sort the list by last attribute (status) change time * <code>-r</code> Reverse the order, for example most recent time last * <code>--full-time</code> Show times down to the millisecond instead of just the minute * <code>-1</code> One entry per line * <code>-m</code> Stream format; list items across the page, separated by commas. * <code>-g</code> Include group but not owner * <code>-o</code> Include owner but not group (when combined with <code>-g</code> both group and owner are suppressed) * <code>-d</code> Show information about a directory or symbolic link, rather than the contents of a directory or the link's target * <code>-F</code> Append a "/" to directory names and a "*" to executable files == Example == 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 [[File system permissions#Notation of traditional Unix permissions|permissions]], the number of [[hard link]]s, owning user, owning group, [[file size|size]], modification date, [[filename|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. <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]] <code>ls</code> provides the <code>--color</code> option<ref>{{Cite web |title=General output formatting (GNU Coreutils 9.1) |url=https://www.gnu.org/software/coreutils/manual/html_node/General-output-formatting.html |access-date=2023-01-07 |website=www.gnu.org}}</ref> 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<ref>{{cite web |url=http://www.freebsd.org/cgi/man.cgi?query=ls |title=FreeBSD Man Pages — ls |access-date=June 23, 2013 }}</ref> 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> == See also == * {{Annotated link|stat (Unix)}} * {{Annotated link|chown}} * {{Annotated link|chgrp}} * {{Annotated link|du (Unix)}} * {{Annotated link|mdls}} * {{Annotated link|User identifier (Unix)}} * {{Annotated link|Group identifier (Unix)}} * {{Annotated link|List of POSIX commands}} * {{Annotated link|Unix directory structure}} == References == {{Reflist}} == External links == {{Wikibooks|Guide to Unix|Commands}} * {{man|cu|ls}} * {{man|1|ls|FreeBSD}} * {{man|1|ls|NetBSD}} * {{man|1|ls|OpenBSD}} * {{man|1|ls|Solaris}} * {{man|1|ls|Linux}} * {{man|1|ls|Plan 9}} * {{man|1|ls|Inferno}} * [http://ftp.gnu.org/pub/gnu/coreutils/ GNU <code>ls</code> source code (as part of coreutils)] * [http://wiki.linuxquestions.org/wiki/Ls <code>ls</code>] at the LinuxQuestions.org wiki {{Unix commands}} {{Plan 9 commands}} {{Core Utilities commands}} [[Category:Multics commands]] [[Category:Standard Unix programs]] [[Category:Unix SUS2008 utilities]] [[Category:Plan 9 commands]] [[Category:Inferno (operating system) commands]] [[Category:IBM i Qshell commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:About
(
edit
)
Template:Annotated link
(
edit
)
Template:Citation
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Core Utilities commands
(
edit
)
Template:Endash
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Plan 9 commands
(
edit
)
Template:Redirect
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Unix commands
(
edit
)
Template:Wikibooks
(
edit
)