World Library  
Flag as Inappropriate
Email this Article

Ls

Article Id: WHEBN0000158682
Reproduction Date:

Title: Ls  
Author: World Heritage Encyclopedia
Language: English
Subject: Cd (command), Plan 9 from Bell Labs, Time (Unix), Hidden file and hidden directory, Shell script
Collection: Standard Unix Programs, Unix Sus2008 Utilities
Publisher: World Heritage Encyclopedia
Publication
Date:
 

Ls

A long file listing with "ls -l" in OpenBSD 5.3

In computing, ls is a command to list 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.

Contents

  • History 1
  • Behavior 2
  • Sample usage 3
  • See also 4
  • Notes 5
  • External links 6

History

An ls utility appeared in the original version of AT&T UNIX. Today, two popular versions of ls are the Free Software Foundation's (part of the GNU coreutils package) and the one released by various BSD variants, such as FreeBSD, OpenBSD, NetBSD, and Apple's Darwin. Both are free software and open source. The name 'ls' comes from a similar command in Multics also named 'ls', short for the word "list".[1]

Behavior

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. 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, permissions, number of hard links, owner, group, size, last-modified date and filename
  • -f do not sort. Useful for directories containing large numbers of files.
  • -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.) This option is not part of the POSIX standard, although implemented in several systems, e.g., GNU coreutils in 1997,[2] FreeBSD 4.5 in 2002,[3] and Solaris 9 in 2002.[4]

In some environments, providing the option --color (for GNU ls) or -G (FreeBSD 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. On the other hand, the FreeBSD implementation uses the termcap database[5] while the GNU program uses its own database which does not necessarily match the termcap data on a given system.[6]

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      
 drwxrwxr-x    2 unixguy staff      48 Jan 26 11:28 directory     
 -rwxrwxr-x    1 unixguy staff      29 Jan 26 14:03 executable    
 prw-r--r--    1 unixguy staff       0 Jan 26 11:50 fifo          
 srw-rw-rw-    1 unixguy staff       0 Jan 26 12:00 socket        
 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.

Sample usage

The following example demonstrates the output of the ls command given two different arguments (pwd is a command that shows the present working directory, or in other words, the folder you are currently in):

$ 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.

drwxr--r--   1 fred  editors   4096  Mar 1  2007 drafts

This means that the letters behind the file descriptor (d), which indicates a folder or 'directory', list three characters to indicate permissions for the owner of 'drafts' (rwx), then the group to which the file belongs (r--), and the rights of others (r--).

'drafts' is a directory (d), the owner of which has the right to read (r) write (w) and execute (x): rwx, group members have (r--), meaning read only, and others have (r--), meaning read only access. See Unix file permission notation for a more detailed description.

See also

Notes

  1. ^ Multics manual page for ls or list command
  2. ^ "(decode_switches): -h and -H override output units.". coreutils.git. 1997-12-31. 
  3. ^ "[base] Log of /stable/10/bin/ls/ls.c". 2001-12-28. 
  4. ^ What's New in the Solaris 9 Operating Environment, Sun Microsystems, 2002 
  5. ^ "FreeBSD Man Pages — ls". Retrieved June 23, 2013. 
  6. ^ "NCURSES — Frequently Asked Questions (FAQ): My terminal doesn't recognize color". Retrieved June 23, 2013. 

External links

This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.