ls -- list directory contents

BSD options. linux options
ls [-ABCFGHLPRTWZabcdefghiklmnopqrstuwx1] [arg ...]

-- terminates options, useful when filenames begin with a -

For a file; display its name and attributes.
For a directory; displays the files in that directory and attributes.

If no operands are given, the contents of the current directory are displayed.
If more than one operand is given (or implied with shell pattern match),

  • non-directory operands are displayed first;
  • directory and non-directory operands are sorted separately and in lexicographical order.

    -a all files
    > /bin/ls -a
    .              bcols.js            fixRpt.sed   makeRpt.sh        rptRows.html
    ..             birdRpt.080410.sed  freq.sql     rpt.0807001.sql   tableBot.html
    RptTable.html  birdRpt.sed         index.html   rpt.sql           tableTop.html
    archve         birdRptTable.html   index.shtml  rptFix.080410.sed tmp
    -A List all entries except for . and ... parent and current (set for the super-user.)
    > /bin/ls -A
    RptTable.html birdRpt.080410.sed fixRpt.sed index.shtml     rpt.sql           tableBot.html
    archve        birdRpt.sed        freq.sql   makeRpt.sh      rptFix.080410.sed tableTop.html
    bcols.js      birdRptTable.html  index.html rpt.0807001.sql rptRows.html      tmp
    -C multi-column output with entries sorted down, the columns.default when output is to a terminal.
    > ls -C
    RptTable.html birdRpt.080410.sed fixRpt.sed index.shtml     rpt.sql           tableBot.html
    archve        birdRpt.sed        freq.sql   makeRpt.sh      rptFix.080410.sed tableTop.html
    bcols.js      birdRptTable.html  index.html rpt.0807001.sql rptRows.html      tmp
         
    -x multi-column output with entries sorted across
    > ls -x
    RptTable.html      archve          bcols.js  birdRpt.080410.sed  birdRpt.sed
    birdRptTable.html  fixRpt.sed      freq.sql  index.html          index.shtml
    makeRpt.sh         rpt.0807001.sql rpt.sql   rptFix.080410.sed   rptRows.html
    tableBot.html      tableTop.html   tmp 
    -1 one entry per line. default when output is not to a terminal.
         RptTable.html
         archve
         bcols.js
         birdRpt.080410.sed
         birdRpt.sed
         birdRptTable.html
         fixRpt.sed
         freq.sql
         index.html
         index.shtml
         makeRpt.sh
         rpt.0807001.sql
         rpt.sql
         rptFix.080410.sed
         rptRows.html
         tableBot.html
         tableTop.html
         tmp
         
    -m Stream output format; list files across the page, separated by commas.

    RptTable.html, archve, bcols.js, birdRpt.080410.sed, birdRpt.sed, birdRptTable.html, fixRpt.sed, freq.sql, index.html, index.shtml, makeRpt.sh, rpt.0807001.sql, rpt.sql, rptFix.080410.sed, rptRows.html, tableBot.html, tableTop.html, tmp

    -l long format. If the output is to a terminal, a total sum for all the file sizes is output first on a line ( in blocks!)
         total 108
         -rw-r--r-- 1 realger1 realger1 12608 Apr 29  2008 RptTable.html
         drwxr-xr-x 2 realger1 realger1  4096 Sep 21 11:31 archve
         -rw-r--r-- 1 realger1 realger1  1582 Jun  8  2008 bcols.js
         -rw-r--r-- 1 realger1 realger1  1030 Jun 20  2007 birdRpt.080410.sed
         -rw-r--r-- 1 realger1 realger1  3123 Apr 29  2008 birdRpt.sed
         -rw-r--r-- 1 realger1 realger1  8676 Nov 15  2007 birdRptTable.html
         -rw-r--r-- 1 realger1 realger1  1130 Jun 12  2008 fixRpt.sed
         -rw-r--r-- 1 realger1 realger1  1461 Sep 12 09:23 freq.sql
         -rw-r--r-- 1 realger1 realger1   167 Mar  1  2007 index.html
         -rw-r--r-- 1 realger1 realger1  3148 Jan 23  2008 index.shtml
         -rwxr-xr-x 1 realger1 realger1  2494 Sep 14 20:16 makeRpt.sh
         -rw-r--r-- 1 realger1 realger1  2369 Jun 26  2008 rpt.0807001.sql
         -rw-r--r-- 1 realger1 realger1  5212 Sep  3  2008 rpt.sql
         -rw-r--r-- 1 realger1 realger1  1211 Oct  9  2007 rptFix.080410.sed
         -rw-r--r-- 1 realger1 realger1 15335 Nov  2 10:24 rptRows.html
         -rw-r--r-- 1 realger1 realger1    21 Oct  9  2007 tableBot.html
         -rw-r--r-- 1 realger1 realger1   640 Jun 12  2008 tableTop.html
         drwxr-xr-x 2 realger1 realger1  4096 Apr 30  2008 tmp
         
    -p display / after directories
    -F include suffixes
    / directories,
    * executables,
    + extended security information
         (Use -@ to display that information)
    @ symbolic link
         (Use -@ to display that information)

    = socket
    % whiteout
    | FIFO
    -G Enable colorized output. environment variable CLICOLOR

    options effecting output sorting
    -f not sorted.
    -S size
    -t time modified before sorting by lexicographical order.
    -c time of last status change -or-
    -u time of last access
    If file system is mounted with noatime access times are not updated.
    -r reverse the order of the sort to get reverse lexicographical order or
    the oldest entries first or smallest files first
     
    -T used with -l option, display complete time information for the file, including
    month, day, hour, minute, second, and year.
           
        drwx------+  59 2006 Dec  7 15:18:01 2008 Downloads
        drwxr-xr-x    2   68 Dec  7 12:06:31 2008 EasyFind
        -rwxr-----    1  262 Sep 17 01:00:00 2007 FTPtest.bat
        -rwxr-----    1   67 Sep 17 01:00:00 2007 FTPtest.cmd
    -e extend the display to include the Access Control List (ACL) info.
    -O the file's flags in a long output. (hidden,
    -o display owner (supressing group)
    -g the group name (supressing owner)in the long format output.
    -n user and group IDs
    -i the file's file serial number (inode number).
    -k the file size in kilobytes, not blocks.
    overrides the environment variable BLOCKSIZE.
    -h human ? sizes. With -l , use unit suffixes: Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte reducing the number of digits to three (n.m) or less
    -s size in file system blocks, important for sparse files ( ex /var/log/lastlog for which -l -l reports incorrect byte count .

    If the output is to a terminal, total bbbbbb for all the file sizes is output on a line before the listing.
    BLOCKSIZE overrides the unit size of 512 bytes.
    -R Recursively list subdirectories
    -d Directories not searched recursively.

    options affecting symbolic link display
    -H Symbolic links on the command line are followed. assumed if none of -F, -d, or -l are specified.
    -L If argument is a symbolic link, list the references rather than the link itself. This option cancels -P .
    -P If argument is a symbolic link, list the link

    -q display non-graphic characters in file names as ?. default when output is to a terminal.
    -w raw displaying of non-printable characters. default when output is not to a terminal.
    -v unedited displaying of non-graphic characters; this is the default when output is not to a terminal.
    -B Binary filenames ; display non-displayable characters in file names as \xxx, where xxx is the numeric value of the character in octal.
    -W Display whiteouts when scanning directories.

    Column formats -1, -C, -x, and -l override each other; the last one specified is used.
    Sort time choices -c(change) and -u(access) override each other; the last one specified isused.
    -B, -b, -w, and -q override each other; the last one specified determines the format used for non-displayable characters. -b As -B, but use C escape codes whenever possible. -H, -L and-P override each other (either partially or fully); they are applied in the order specified.

    Default, one entry per line to standard output; to terminals or with -C or -x (multi column formats.)

    File information is displayed with blanks separating the information associated with the -i, -s, and -l options.

    The Long Format

    -l displays :
    type, mode, number of links, owner , group , number of bytes in the file, month, day-of-month file was last modified, hour file last modified, minute file last modified, and the pathname.

    If the modification time of the file is more than 6 months away, the year is displayed instead of the hour and minutes.

    If the owner or group names are not known (example they have been deleted), or with -n numeric ID's are displayed.

    For character special or block special files the major and minor device numbers for the file are displayed in the size field.

    For symbolic links a -> and the pathname of the linked-to file is displayed

    The type character describes the type of file :

    - Regular file.
    d Directory.
    l Symbolic link.
    b Block special file.
    c Character special file.
    s Socket link.
    p FIFO.

    The mode, the permssion flags, are three fields of three characters each (ex: rwxrwxr-x ) :

  • fields: user whos owns the file , group members , and others.
  • Each field has three character positions:
    1. r the file is readable; - not readable.
    2. w the file is writable; - not writable.
    3. The first of the following that applies:
      • S the file is not executable
        • in the owner permissions set-user-ID mode is set.
        • in the group permissions set-group-ID mode is set.
      • s the file is executable
        • in the owner permissions set-user-ID mode is set.
        • If in the group permissions set-group-ID mode is set.
      • x file is executable or directory is searchable.
      • - file is neither readable, writable, executable, nor set-user-ID nor set-group-ID mode, nor sticky.
        These next two apply only to the third character in the last field (other permissions).
      • T sticky bit is set (mode 1000), but not execute or search permission.
      • t sticky bit is set (mode 1000), and is searchable or executable.

        (See chmod or sticky for more details)

      • + or
      • @ the file or directory has extended security information

    total nnnnnn number of 512-byte blocks used by the files in the directory is displayed on a line by itself immediately before the information for the files in the directory.
    EXAMPLES
    Sort by size (and shows why ls does not need a separate option for this):

    ls -l | sort -n +4

    -r reverse sort order.

    exits 0 on success, and >0 if an error occurs.

    ENVIRONMENT variables

    BLOCKSIZE default is 512.

    CLICOLOR Use ANSI color sequences to distinguish file types. See LSCOLORS.
    In addition to the file types mentioned in -F extra attributes (setuid bit set, etc.) are displayed.
    Dependent terminal type with the proper termcap(5) capabilities. To display the colors in an xterm, the TERM variable may be set to xterm‑color. Other terminal types may require similar adjustments.
    Disabled if the output isn't directed to a terminal unless CLICOLOR_FORCE is defined.
    CLICOLOR_FORCE if set, color sequences are output if not directed to a terminal.

    LSCOLORS Defines colors used when colors are enabled with CLICOLOR.
    String of pairs of the format fb, where f is the foreground color and b is the background color.

    a black b red c green d brown
    e blue f magenta g cyan h light grey
    A bold black B bold red C bold green D bold brown, usually shows up as yellow
    E bold blue F bold magenta G bold cyan H bold light grey; looks like bright white
    x default foreground or background

    The order of the attributes :
    dir, symlink, socket, pipe, executable, block serial, character special, executable+SUID, executable+GUID, executabl+sticky+w=others, directory+w=others

    Default "exfxcxdxbxegedabagacad",
    i.e. blue foreground and default background for regular directories, magenta for symLinks, green for sockets, …black on red for setuid executables, etc.

    TERM CLICOLOR depends on a terminal type with color capabilities.

    COLUMNS column width for displaying multiple-text-column output.

    LS_COLWIDTHS a colon-delimited list of minimum column widths. Unreasonable and insufficient widths are ignored (zero signifies a dynamically sized column).
    Not all columns have changeable widths.
    inode, block count, number of links, user name, group name, flags, file size, file name.

    LANG The locale to use when determining the order of day and month in the long -l format output. See environ .

    TZ timezone to use when displaying dates. See environ(7) for more information.

    SEE ALSO chflags, chmod, sort, xterm, compat, termcap, symlink, sticky

    May 19, 2002 BSD