ls
Operating system | Multics, Unix, Unix-like, Plan 9, Inferno, MSX-DOS, Mac OS |
---|---|
Type | Command |
License |
In computing, ls
is a command to list computer files in Unix and Unix-like operating systems. ls
is specified by POSIX and the Single UNIX Specification. When invoked without any arguments, ls lists the files in the current working directory. The command is also available in the EFI shell.[1] In other environments, such as DOS, OS/2, and Microsoft Windows, similar functionality is provided by the dir
command. The numerical computing environments MATLAB and GNU Octave include an ls
function with similar functionality.[2][3]
History[edit]
An ls
utility appeared in the first version of AT&T UNIX, the name inherited from a similar command in Multics also named 'ls', short for the word "list".[4][5][6] 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.[7]
An ls
command is also part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.[8]
Today, the two popular versions of ls
are the one provided with the GNU coreutils package, and that released by various BSD variants. Both are free software and open source, and have only minor syntax differences. The version of ls
bundled in GNU coreutils was written by Richard Stallman and David MacKenzie.[9]
The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[10]
Behavior[edit]
Unix and Unix-like operating systems maintain the idea of a current working directory, that is, where one is currently positioned in the hierarchy of directories. When invoked without any arguments, ls
lists the files in the current working directory. If another directory is specified, then ls
will list the files there, and in fact the user may specify any list of files and directories to be listed.
Files names starting with "." are not listed unless -a
(show all) is specified, -A
(show all except "." and "..") is specified, or the files are specified explicitly.
Without options, ls
displays files names only. The most common options to display additional information are:
-l
long format, displaying Unix file types, permissions, number of hard links, owner, group, size, last-modified date and filename-F
append a "/" to directory names and a "*" to executable files.-g
display group but not owner-o
display owner but not group (when combined with-g
both group and owner are suppressed)-d
shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.-h
output sizes in human readable format. (e.g., 1K, 234M, 2G, etc.) This option is not part of the POSIX standard, although implemented in several systems, e.g., GNU coreutils in 1997,[11] FreeBSD 4.5 in 2002,[12] and Solaris 9 in 2002.[13]
Additional options controlling how files are displayed include:
-f
do not sort. Useful for directories containing large numbers of files.-t
sort the list of files by modification time. (default is alphabetically)-1
(one) force output to be one entry per line.-R
recursively list files in subdirectories and their subdirectories …-u
lists files' last access time instead of their last modified time.--full-time
to show times with seconds and milliseconds instead of down to the minute.
It is frequently possible to highlight different types of files with different colors, instead of with characters as -F
would. This is an area where the two main ls
versions differ:
- GNU
ls
uses the--color
option; checks the Unix file type, the file permissions and the file extension and uses its own database to control colors maintained using dircolors. - FreeBSD
ls
uses the-G
option; checks only the Unix file type and file permissions. and uses the termcap database[14]
When the option to use color to indicate file types is selected, the output might look like:
-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
Sample usage[edit]
The following example demonstrates the output of the ls
command given two different arguments:
$ ls -l
drwxr--r-- 1 fjones editors 4096 drafts
-rw-r--r-- 1 fjones editors 30405 edition-32
-r-xr-xr-x 1 fjones bookeepers 8460 edit.sh
$ ls -F
drafts/
edition-32
edit.sh*
In the above example, the user fjones
has a directory named drafts
, a regular file named edition-32
, and an executable named edit.sh
in his home directory. ls
uses Unix file permission notation to define the access for the user(i.e. himself), group members for various groups and other users.
drwxr--r-- 1 fred editors 4096 Mar 1 2007 drafts
In this example, drafts is a directory (denoted by the file descriptor d), and the characters after this indicate the permissions:
- rwx: the owner (fjones) has the right to read (r), write (w) and execute (x)
- r--: users who are members of the editors group have read-only permissions; write and execute are not permitted, as denoted by the hyphen characters (-)
- r--: others (users aside from the owner or members of editors) have read-only permissions; write and execute are not permitted
See also[edit]
- chown
- chgrp
- du (Unix)
- stat (Unix)
- mdls
- User identifier (Unix)
- Group identifier (Unix)
- List of Unix commands
- Unix directory structure
References[edit]
- ^ "EFI Shells and Scripting". Intel. Retrieved 2013-09-25.
- ^ "List folder contents - MATLAB ls".
- ^ "Function Reference: Ls".
- ^ Multics manual page for ls or list command
- ^ "A Brief History of the 'ls' command", Eric Fischer, The Linux Documentation Project
- ^ "Multics programmer's manual - Commands and active functions" (PDF). p. 397.
- ^ The Single UNIX Specification, Issue 7 from The Open Group – Commands & Utilities Reference,
- ^ MSX-DOS2 Tools User's Manual by ASCII Corporation
- ^ Linux General Commands Manual; – FreeBSD General Commands Manual –
- ^ "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
- ^ "(decode_switches): -h and -H override output units". coreutils.git. 1997-12-31.
- ^ "[base] Log of /stable/10/bin/ls/ls.c". 2001-12-28.
- ^ What's New in the Solaris 9 Operating Environment, Sun Microsystems, 2002
- ^ "FreeBSD Man Pages — ls". Retrieved June 23, 2013.
External links[edit]
The Wikibook Guide to Unix has a page on the topic of: Commands |
- The Single UNIX Specification, Issue 7 from The Open Group – Commands & Utilities Reference,
- FreeBSD General Commands Manual –
- NetBSD General Commands Manual –
- OpenBSD General Commands Manual –
- Solaris 10 User Commands Reference Manual –
- Linux User Commands Manual –
- Plan 9 Programmer's Manual, Volume 1 –
- Inferno General commands Manual –
- GNU
ls
source code (as part of coreutils) ls
at the LinuxQuestions.org wiki