Ls
Encyclopedia
In computing
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...

, ls is a command to list files in Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 and Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 operating systems. ls is specified by POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

 and the Single UNIX Specification
Single UNIX Specification
The Single UNIX Specification is the collective name of a family of standards for computer operating systems to qualify for the name "Unix"...

.

History

An ls utility appeared in the original version of AT&T
AT&T
AT&T Inc. is an American multinational telecommunications corporation headquartered in Whitacre Tower, Dallas, Texas, United States. It is the largest provider of mobile telephony and fixed telephony in the United States, and is also a provider of broadband and subscription television services...

 UNIX
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

. Today, two popular versions of ls are the Free Software Foundation
Free Software Foundation
The Free Software Foundation is a non-profit corporation founded by Richard Stallman on 4 October 1985 to support the free software movement, a copyleft-based movement which aims to promote the universal freedom to create, distribute and modify computer software...

's (part of the GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

 coreutils
GNU Core Utilities
The GNU Core Utilities or coreutils is a package of GNU software containing many of the basic tools, such as cat, ls, and rm, needed for Unix-like operating systems...

 package) and the one released by various BSD
Berkeley Software Distribution
Berkeley Software Distribution is a Unix operating system derivative developed and distributed by the Computer Systems Research Group of the University of California, Berkeley, from 1977 to 1995...

 variants, such as FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

, OpenBSD
OpenBSD
OpenBSD is a Unix-like computer operating system descended from Berkeley Software Distribution , a Unix derivative developed at the University of California, Berkeley. It was forked from NetBSD by project leader Theo de Raadt in late 1995...

, NetBSD
NetBSD
NetBSD is a freely available open source version of the Berkeley Software Distribution Unix operating system. It was the second open source BSD descendant to be formally released, after 386BSD, and continues to be actively developed. The NetBSD project is primarily focused on high quality design,...

, and Apple Computer
Apple Computer
Apple Inc. is an American multinational corporation that designs and markets consumer electronics, computer software, and personal computers. The company's best-known hardware products include the Macintosh line of computers, the iPod, the iPhone and the iPad...

's Darwin
Darwin (operating system)
Darwin is an open source POSIX-compliant computer operating system released by Apple Inc. in 2000. It is composed of code developed by Apple, as well as code derived from NeXTSTEP, BSD, and other free software projects....

. Both are free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

 and open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

.

Behavior

Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 and Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 operating systems maintain the idea of a current working directory
Working directory
In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with each process. When the process refers to a file using a simple file name or relative path , the reference is interpreted relative to the current working directory of...

, that is, where one is currently positioned in the hierarchy of directories
Directory (file systems)
In computing, a folder, directory, catalog, or drawer, is a virtual container originally derived from an earlier Object-oriented programming concept by the same name within a digital file system, in which groups of computer files and other folders can be kept and organized.A typical file system may...

.

When invoked without any arguments, ls lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed.

Files whose names start with "." are not listed, unless the -a flag is specified, the -A flag is specified, or the files are specified explicitly.
Without options, ls displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
  • -l long format, displaying Unix file types
    Unix file types
    For normal files in the file system, Unix does not impose or provide any internal file structure.This implies that from the point of view of the operating system, there is only one file type....

    , permissions, number of hard link
    Hard link
    In computing, a hard link is a directory entry that associates a name with a file on a file system. . The term is used in file systems which allow multiple hard links to be created for the same file. This has the effect of creating multiple names for the same file, causing an aliasing effect: e.g...

    s, owner, group, size, date, and filename
  • -F appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
  • -a lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
  • -R recursively lists subdirectories. The command ls -R / would therefore list all files.
  • -d shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
  • -t sort the list of files by modification time.
  • -h print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)


In some environments, providing the option --color (for GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

 ls) or -G (FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

 ls) causes ls to highlight different types of files with different colors, instead of with characters as -F would. To determine what color to use for a file, GNU ls checks the Unix file type, the file permissions, and the file extension, while FreeBSD ls checks only the Unix file type and file permissions.

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

brw-r--r-- 1 unixguy staff 64, 64 Jan 27 05:52 block
crw-r--r-- 1 unixguy staff 64, 255 Jan 26 13:57 character
-rw-r--r-- 1 unixguy staff 290 Jan 26 14:08 compressed.gz
-rw-r--r-- 1 unixguy staff 331836 Jan 26 14:06 data.ppm
drwxrwx--x 2 unixguy staff 48 Jan 26 11:28 directory
-rwxrwx--x 1 unixguy staff 29 Jan 26 14:03 executable
prw-r--r-- 1 unixguy staff 0 Jan 26 11:50 fifo
lrwxrwxrwx 1 unixguy staff 3 Jan 26 11:44 link -> dir
-rw-rw---- 1 unixguy staff 217 Jan 26 14:08 regularfile


ls has a large number of other options (see: man ls). It is a frequently used tool that provides an interface to the file system via the command line.

On some systems (e.g. PCLinuxOS
PCLinuxOS
PCLinuxOS, often shortened to PCLOS, is a GNU/Linux distribution, with KDE Plasma Desktop as its default user interface. It is a primarily free software operating system for personal computers aimed at ease of use...

), ls has an alias of just l. Many systems also alias ls -l to ll or ls -la to la (e.g. PC-BSD
PC-BSD
PC-BSD is a Unix-like, desktop-oriented operating system based on FreeBSD. It aims to be easy to install by using a graphical installation program, and easy and ready-to-use immediately by providing KDE SC as the pre-installed graphical user interface. PC-BSD provides official binary nVidia and...

).

Sample usage

The following example demonstrates the output of the ls command given two different arguments:

$ pwd
/home/fred
$ ls -l
drwxr--r-- 1 fred editors 4096 drafts
-rw-r--r-- 1 fred editors 30405 edition-32
-r-xr-xr-x 1 fred fred 8460 edit
$ ls -F
drafts/
edition-32
edit*

In this example, the user fred has a directory named drafts, a regular file called edition-32, and an executable named edit in his home directory. ls uses unix file permission notation to indicate which users or groups are allowed to access each file or directory.

This means, in short, that the first column lists permissions for: user (u), owning group (g), and others (o)

drwxr--r-- 1 fred editors 4096 Mar 1 2007 drafts
which maps to
duuugggooo (hard link
Hard link
In computing, a hard link is a directory entry that associates a name with a file on a file system. . The term is used in file systems which allow multiple hard links to be created for the same file. This has the effect of creating multiple names for the same file, causing an aliasing effect: e.g...

 count) owner group size modification_date name

meaning that drafts is a directory, the user has rwx, group members have r, and others have r (read) access. See unix file permission notation for a more detailed description.

See also

  • dir (command)
  • chown
    Chown
    The chown command is used on Unix-like systems to change the owner of a file. In most implementations, it can only be executed by the superuser. Unprivileged users who wish to change the group of a file that they own may use chgrp.-Usage examples:These examples illustrate typical syntax and use...

  • chgrp
    Chgrp
    The chgrp command is used by unprivileged users on Unix-like systems to change the group associated with a computer file...

  • du (Unix)
    Du (Unix)
    du is a standard Unix program used to estimate file space usage—space used under a particular directory or files on a file system.- Specification :...

  • mdls
  • User identifier (Unix)
    User identifier (Unix)
    Unix-like operating systems identify users within the kernel by an unsigned integer value called a user identifier, often abbreviated to UID or User ID...

  • Group identifier (Unix)
    Group identifier (Unix)
    In Unix-like systems, multiple users can be categorized into groups. POSIX and conventional Unix file system permissions are organized into three classes, user, group, and others. The use of groups allows additional abilities to be delegated in an organized fashion, such as access to disks,...

  • List of Unix programs
  • Unix directory structure
    Unix directory structure
    In Unix and Unix-like operating systems, the Unix directory structure is a convention for filesystem layout.Several attempts exist to standardize the Unix filesystem layout, such as the "Filesystem Hierarchy Standard," however, it is targeted primarily at Linux...


External links

  • ls at the LinuxQuestions.org wiki
  • ls specified by the Single Unix Specification
    Single UNIX Specification
    The Single UNIX Specification is the collective name of a family of standards for computer operating systems to qualify for the name "Unix"...

  • GNU ls source code (as part of coreutils) — manual pages from GNU
    GNU
    GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

     coreutils.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK