Ls Explained

ls
Author:coreutils: Richard Stallman and David MacKenzie
Developer:Various open-source and commercial developers
Programming Language:C
Operating System:Multics, Unix, Unix-like, Plan 9, Inferno, MSX-DOS
Genre:Command
License:coreutils

GPLv3+
BusyBox: GPL-2.0-only
Toybox: 0BSD
Plan 9: MIT License

ls 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),[1] EFI,[2] and MSX-DOS (via MSX-DOS2 Tools).[3]

The numerical computing environments MATLAB and GNU Octave include an ls command with similar functionality.[4] [5]

An ls command appeared in the first version of AT&T UNIX. The name inherited from Multics and is short for "list".[6] [7] [8] 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 [[dir (command)|dir]]. Apple DOS for the Apple II uses .

Behavior

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:

Example

The following example shows the long form output:$ ls -ldrwxr--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

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.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ 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

Some implementations support color output to indicate metadata. GNU ls provides the --color option[11] which enables using a database to control colors maintained using dircolors. FreeBSD ls provides the -G option which enables using the termcap database[12] 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

External links

Notes and References

  1. Web site: Native Win32 ports of some GNU utilities. unxutils.sourceforge.net. 2025-08-09. 2006-02-09. https://web.archive.org/web/20060209022842/http://unxutils.sourceforge.net/. live.
  2. Web site: EFI Shells and Scripting . deviated . https://web.archive.org/web/20130927203229/http://software.intel.com/en-us/articles/efi-shells-and-scripting/ . September 27, 2013 . 2013-09-25 . Intel.
  3. Web site: MSX-DOS2 Tools User's Manual - MSX-DOS2 TOOLS γƒ¦γƒΌγ‚ΆγƒΌγ‚Ίγƒžγƒ‹γƒ₯をル. April 1, 1993. Internet Archive.
  4. Web site: List folder contents - MATLAB ls. 2019-04-06. 2012-10-09. https://web.archive.org/web/20121009233800/https://www.mathworks.com/help/matlab/ref/ls.html. live.
  5. Web site: Function Reference: Ls . Octave Forge . 2019-04-06 . 2019-04-06 . https://web.archive.org/web/20190406171041/https://octave.sourceforge.io/octave/function/ls.html . live .
  6. Web site: 14 February 1985 . Multics manual page for ls or list command .
  7. Web site: A Brief History of the 'ls' command . Eric . Fischer . . 2022-12-09 . 2023-01-02 . https://web.archive.org/web/20230102040116/https://tldp.org/LDP/LG/issue48/fischer.html . live .
  8. Web site: Multics programmer's manual - Commands and active functions . 397 .
  9. Web site: (decode_switches): -h and -H override output units. . coreutils.git . 1997-12-31 . 2014-11-05 . 2019-12-10 . https://web.archive.org/web/20191210055340/https://git.savannah.gnu.org/cgit/coreutils.git/commit/src/ls.c?id=b76a4533046163978f7517f9ea6d3307bfa0a98a . live .
  10. Web site: [base] Log of /stable/10/bin/ls/ls.c ]. 2001-12-28 . 2014-11-05 . 2015-09-21 . https://web.archive.org/web/20150921164916/http://svnweb.freebsd.org/base?view=revision . live .
  11. Web site: General output formatting (GNU Coreutils 9.1) . 2023-01-07 . www.gnu.org . 2023-01-07 . https://web.archive.org/web/20230107084005/https://www.gnu.org/software/coreutils/manual/html_node/General-output-formatting.html . live .
  12. Web site: FreeBSD Man Pages - ls . June 23, 2013 . September 22, 2013 . https://web.archive.org/web/20130922040709/http://www.freebsd.org/cgi/man.cgi?query=ls . live .