ls
![]() long file listing with " ls --color=auto -l " in linux showing various modes, date formats, colors and appended indicators (executables and directories). | |
Original author(s) | coreutils: Richard Stallman and David MacKenzie |
---|---|
Developer(s) | Various open-source and commercial developers |
Written in | C |
Operating system | Multics, Unix, Unix-like, Plan 9, Inferno, MSX-DOS |
Type | Command |
License | coreutils: GPLv3+ BusyBox: GPL-2.0-only Toybox: 0BSD Plan 9: MIT License |
In computing, ls
is a command to list computer files and directories in Unix and Unix-like operating systems. It is specified by POSIX and the Single UNIX Specification.
It is available in the EFI shell.[1], as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[2] or as part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.[3]
The numerical computing environments MATLAB and GNU Octave include an ls
function with similar functionality.[4][5]
In other environments, such as DOS, OS/2, and Microsoft Windows, similar functionality is provided by the dir
command.
As with most utilities the different implementations have different options. Check the documentation provided with the command for correct usage and options.
History
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".[6][7][8] 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.[9]
Command syntax
ls [options] [file… | directory …]
Behavior
Unix and Unix-like operating systems maintain the idea of a working directory. When invoked without arguments, ls
lists the files in the working directory. If a directory is specified, the files in that directory are listed. The arguments may contain a multiple files and directories.
Names starting with "." are hidden. The directory "." refers to the working directory and ".." refers to its parent directory. These are not shown by default. With -a
(all) hidden files are shown. Using -A
(All including "." and ".." ). File names specified explicitly (for example ".secret*
" ) are always listed.
Without options, ls
displays names only. Multiple options may be combined.
Common options include:
-l
long format, displaying Unix file types, permissions, number of hard links, owner, group, size, last-modified date-time and name. If the modified date is older than 6 months the time is replaced with the year. Some implementations add additional flags to permissions.-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,[10] FreeBSD 4.5 in 2002,[11] and Solaris 9 in 2002.[12]
Additional options controlling how items are displayed include:
-R
Recursively list items in subdirectories and subdirectories …-t
sort the list by modification time. (default 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
to show times with seconds and milliseconds instead of down to 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
shows 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.
It is may be possible to highlight different types of items with different colors. This is an area where implementations 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[13]
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: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
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
The above example shows the "d" )(directory) or "-" (file) indicator, Unix file permission notation, number of Hard_links (1 or 3). In the working directory the owner fjones
has a directory named drafts
, a regular file named edition-32
, and an old executable named edit.sh
.
See also
- stat (Unix)
- chown
- chgrp
- du (Unix)
- mdls
- User identifier (Unix)
- Group identifier (Unix)
- List of Unix commands
- Unix directory structure
References
- ^ "EFI Shells and Scripting". Intel. Retrieved 2013-09-25.
- ^ "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
- ^ MSX-DOS2 Tools User's Manual by ASCII Corporation
- ^ "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, Version 4 from The Open Group – Shell and Utilities Reference,
- ^ "(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
![](http://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/40px-Wikibooks-logo-en-noslogan.svg.png)
- The Single UNIX Specification, Version 4 from The Open Group – Shell and Utilities Reference,
- FreeBSD General Commands Manual –
- NetBSD General Commands Manual –
- OpenBSD General Commands Manual –
- Solaris 11.4 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