Jump to content

ls

From Wikipedia, the free encyclopedia
ls
Original author(s)coreutils:Richard Stallmanand David MacKenzie
Developer(s)Variousopen-sourceandcommercialdevelopers
Written inC
Operating systemMultics,Unix,Unix-like,Plan 9,Inferno,MSX-DOS
TypeCommand
Licensecoreutils:GPLv3+
BusyBox:GPL-2.0-only
Toybox:0BSD
Plan 9:MIT License

Incomputing,lsis acommandto listcomputer filesand directories inUnixandUnix-likeoperating systems. It is specified byPOSIXand theSingle UNIX Specification.

It is available in theEFI shell,[1]as a separate package forMicrosoft Windowsas part of theUnxUtilscollection ofnativeWin32portsof commonGNUUnix-like utilities,[2] or as part ofASCII'sMSX-DOS2 ToolsforMSX-DOSversion 2.[3]

Thenumerical computingenvironmentsMATLABandGNU Octaveinclude anls function with similar functionality.[4][5]

In other environments, such asDOS,OS/2,andMicrosoft Windows,similar functionality is provided by thedircommand.

History

[edit]

Anlsutility appeared in the first version ofAT&TUNIX,the name inherited from a similar command inMulticsalso named 'ls', short for the word "list".[6][7][8]lsis part of theX/OpenPortability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and theSingle Unix Specification.[9]

Behavior

[edit]

UnixandUnix-likeoperating systems maintain the idea of aworking directory.When invoked withoutarguments,lslists the files in the working directory. If a directory is specified as an argument, the files in that directory are listed; if a file is specified, that file is listed. Multiple directories and files may be specified.

In many Unix-like systems, names starting with adot(.) arehidden.Examples are.,which refers to the working directory, and..,which refers to its parent directory. Hidden names are not shown by default. With-a,all names, including all hidden names, are shown. Using-Ashows all names, including hidden names, except for.and...File names specified explicitly (for examplels.secret) are always listed.

Without options,lsdisplays names only. The different implementations have different options, but common options include:

Additional options controlling how items are displayed include:

  • -RRecursively list items in subdirectories.
  • -tSort the list by modification time (default sort is Alpha betically).
  • -uSort the list by last access time.
  • -cSort the list by last attribute (status) change time.
  • -rReverse the order, for example most recent time last.
  • --full-timeShow times down to the second and millisecond instead of just the minute.
  • -1One entry per line.
  • -mStream format; list items across the page, separated by commas.
  • -gInclude group but not owner.
  • -oInclude owner but not group (when combined with-gboth group and owner are suppressed).
  • -dShow information about a directory or symbolic link, rather than the contents of a directory or the link's target.
  • -FAppend a "/" to directory names and a "*" to executable files.

It may be possible to highlight different types of items with different colors. This is an area where implementations differ:

  • GNUlsuses the--coloroption;[13]it checks the Unix file type, the file permissions and the file extension and uses its own database to control colors maintained usingdircolors.
  • FreeBSDlsuses the-Goption; it checks only the Unix file type and file permissions and uses thetermcapdatabase[14]

When the option to use color to indicate item types is selected, the output might look like:

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

Sample usage

[edit]

The following example demonstrates the output of the command:

$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

Each line shows thed(directory) or-(file) indicator,Unix file permission notation,number ofhard links(1 or 3), the file's owner, the file's group, the file size, the modification date/time, and the file name. In the working directory, the ownerfjoneshas a directory nameddrafts,a regular file namededition-32,and an executable namededit.shwhich 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
|│ │ │ ┌── number of hard links
|│ │ │ │ ┌── owner
|│ │ │ │ │ ┌── user group
|│ │ │ │ │ │ ┌── file size in bytes
|│ │ │ │ │ │ │ ┌── last modified on
|│ │ │ │ │ │ │ │ ┌── filename
-rw-r--r-- 3 fjones editors 30405 Mar 2 12:52 edition-32

See also

[edit]

References

[edit]
  1. ^"EFI Shells and Scripting".Intel.Archived fromthe originalon September 27, 2013.Retrieved2013-09-25.
  2. ^"Native Win32 ports of some GNU utilities".unxutils.sourceforge.net.
  3. ^"MSX-DOS2 Tools User's Manual - MSX-DOS2 TOOLS ユーザーズマニュアル".April 1, 1993 – via Internet Archive.
  4. ^"List folder contents - MATLAB ls".
  5. ^"Function Reference: Ls".Octave Forge.
  6. ^"Multics manual page for ls or list command".14 February 1985.
  7. ^Fischer, Eric."A Brief History of the 'ls' command".The Linux Documentation Project.
  8. ^"Multics programmer's manual - Commands and active functions"(PDF).p. 397.
  9. ^ls– Shell and Utilities Reference,The Single UNIX Specification,Version 4 fromThe Open Group
  10. ^"(decode_switches): -h and -H override output units".coreutils.git. 1997-12-31.
  11. ^"[base] Log of /stable/10/bin/ls/ls.c".2001-12-28.
  12. ^What's New in the Solaris 9 Operating Environment,Sun Microsystems, 2002
  13. ^"General output formatting (GNU Coreutils 9.1)".gnu.org.Retrieved2023-01-07.
  14. ^"FreeBSD Man Pages — ls".RetrievedJune 23,2013.
[edit]