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. 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
function with similar functionality.
|Operating system||Multics, Unix, Unix-like, Plan 9, Inferno, MSX-DOS|
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".
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.
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.
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.
ls displays files names only. The most common options to display additional information are:
-llong format, displaying Unix file types, permissions, number of hard links, owner, group, size, last-modified date and filename
-Fappend a "/" to directory names and a "*" to executable files.
-gdisplay group but not owner
-odisplay owner but not group (when combined with
-gboth group and owner are suppressed)
-dshows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
-houtput 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, FreeBSD 4.5 in 2002, and Solaris 9 in 2002.
Additional options controlling how files are displayed include:
-fdo not sort. Useful for directories containing large numbers of files.
-tsort the list of files by modification time. (default is alphabetically)
-1(one) force output to be one entry per line.
-Rrecursively list files in subdirectories and their subdirectories …
-ulists files' last access time instead of their last modified time.
-clists files' last inode change time instead of the last modified time.
--full-timeto 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:
--coloroption; checks the Unix file type, the file permissions and the file extension and uses its own database to control colors maintained using dircolors.
-Goption; checks only the Unix file type and file permissions. and uses the termcap database
When the option to use color to indicate file types is selected, the output might look like:
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:
|The Wikibook Guide to Unix has a page on the topic of: Commands|
lssource code (as part of coreutils)
lsat the LinuxQuestions.org wiki