ls -- list directory contents

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

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,

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

    -a all files. default supresses names begining with a dot.
    /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.
    > /bin/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 > /bin/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 ( this is 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 *, symbolic link @, extended security information +,
                                socket =, whiteout %, FIFO |
    -G Enable colorized output. environment variable CLICOLOR

    options effecting output sorting
    -S Sort files by size
    -t Sort by time modified (most recently modified first) before sorting by lexicographical order.
    -u Use time of last access, instead of last modification of the file for sorting (-t) or displaying (-l).
    -c Use time when file status was last changed for sorting or displaying.
    -r reverse the order of the sort to get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size (-S) flag).
    -f Output is not sorted.
    -T used with -l option, display complete time information for the file, including
    month, day, hour, minute, second, and year.
           
        drwx------+  59 dgerman  staff      2006 Dec  7 15:18:01 2008 Downloads
        drwxr-xr-x    2 dgerman  staff        68 Dec  7 12:06:31 2008 EasyFind
        -rwxr-----    1 dgerman  staff       262 Sep 17 01:00:00 2007 FTPtest.bat
        -rwxr-----    1 dgerman  staff        67 Sep 17 01:00:00 2007 FTPtest.cmd
    -e display the Access Control List (ACL) info.
    -O include the file flags in a long output.
    -o display owner (supressing group)
    -g display the group name (supressing owner)in the long format output.
    -n display user and group IDs
    -i display the file's file serial number (inode number).
    -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
    -k display the file size in kilobytes, not blocks.
    overrides the environment variable BLOCKSIZE.
    -s number of file system blocks used, important for sparse files ( ex /var/log/lastlog for which -l -l reports incorrect byte count .
    If the output is to a terminal, a total sum 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 determines the format used. -c and -u override each other; the last one specified determines the file time used. -B, -b, -w, and -q override each other; the last one specified determines the format used for non-displayable characters. code>-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.

    By default, ls lists one entry per line to standard output; the exceptions are to terminals or when the -C or -x options are specified.

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

    The Long Format

    If the -l option is given, the following information is displayed for each file:
    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.

    If the file is a character special or block special file, the major and minor device numbers for the file are displayed in the size field.

    If the file is a symbolic link the pathname of the linked-to file is preceded by ->

    The file mode displayed under the -l option consists of the entry type, owner permissions, and group permissions. The entry 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.

    Next, 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)

    If the file or directory has extended security information, the permissions field is followed by a +.

    For directories the total 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
    The following is how to do an ls listing sorted by size (and shows why ls does not need a separate option for this):

    ls -l | sort -n +4

    -r reverse sort order.

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

    ENVIRONMENT variables

    BLOCKSIZE the block counts will be displayed in units of that size block; 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. The colorization is dependent on a terminal type with the proper termcap(5) capabilities. The default cons25 console has the proper capabilities. To display the colors in an xterm, the TERM variable must be set to xterm‑color. Other terminal types may require similar adjustments. Colorization is 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.

    COLUMNS If this variable contains a string representing a decimal integer, it is used as the column position width for displaying multiple-text-column output. The ls utility cal- culates how many pathname text columns to display based on the width provided. (See -C and -x.)

    LSCOLORS The value of this variable describes the colors used for which attribute when colors are enabled with CLICOLOR. This string is a concatenation of pairs of the format fb, where f is the foreground color and b is the background color.

    The color designators are:

      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 : directory, symbolic link, socket, pipe, executable, block serial, character special, executable+SUID, executable+GUID, executabl+sticky+w=others, directory+w=others

    The default is "exfxcxdxbxegedabagacad", i.e. blue foreground and default background for regular directories, black foreground and red background for setuid executables, etc.

    LS_COLWIDTHS a colon-delimited list of minimum column widths. Unreasonable and insufficient widths are ignored (thus 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.

    TERM The CLICOLOR functionality depends on a terminal type with color capabilities.

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

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

    The group field is now automatically included in the long listing for files in order to be compatible with the IEEE Std 1003.2 (POSIX.2) specification.

    SEE ALSO chflags(1), chmod(1), sort(1), xterm(1), compat(5), termcap(5), symlink(7), sticky(8)

    May 19, 2002 BSD