Home OS X
OS X Syntax

ls

List information about FILEs, by default the current directory.

SYNTAX
      ls [-Option(s)] [file ...]

      ls-F [-Option(s)] [file ...]
	       This built-in is just like `ls -F', but much faster.

      l        List files in long format `ls -l'

      ll       List files in long format, showing invisible files `ls -la'

OPTIONS

     -A	     List all entries except for . and ...
             Always set for the superuser.

     -a	     Include directory entries whose names begin with a dot (.).

     -B	     Force printing of non-printable characters (as defined by
	     ctype(3) and current locale settings) in file names as \xxx,
	     where xxx is the numeric value of the character in octal.

     -b	     As -B, but use C escape codes whenever possible.

     -C	     Force multi-column output; this is the default when output is to
	     a terminal.

     -c	     Use time when file status was last changed for sorting or print-
	     ing.

     -d	     Directories are listed as plain files (not searched recursively).

     -F	     Display a slash `/' immediately after each pathname that is a
	     directory, an asterisk `*' after each that is executable, an at
	     sign `@' after each symbolic link, an equals sign `=' after
	     each socket, a percent sign `%' after each whiteout, and a ver-
	     tical bar `|' after each that is a FIFO.

     -f	     Output is not sorted.

     -G	     Enable colour output.  This option is equivalent to defining
	     CLICOLOR in the environment.  (See below.)

     -g	     This option is deprecated.

     -H	     Symbolic links on the command line are followed.  This option is
	     assumed if none of the -F, -d, or -l options are specified.

     -h	     When used with the -l option, use unit suffixes: Byte, Kilobyte,
	     Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the
	     number of digits to three or less using base 2 for sizes.

     -i	     For each file, print the file's file serial number 
	     (inode number).

     -k	     If the -s option is specified, print the file size allocation in
	     kilobytes, not blocks.  This option overrides the environment
	     variable BLOCKSIZE.

     -L	     If argument is a symbolic link, list the file or directory the
	     link references rather than the link itself.  This option cancels
	     the -P option.

     -l	     List in long format. Ownership, Date/Time etc
             For terminal output, a total sum of all the file sizes is 
	     output on a line before the long listing.
	     If the file is a symbolic link the pathname of the linked-to file is
	     preceded by ->
                 The entry type character describes the type of file:
	     	   b	 Block special file.
	     	   c	 Character special file.
	     	   d	 Directory.
	     	   l	 Symbolic link.
	     	   s	 Socket link.
	     	   p	 FIFO.
	     	   -	 Regular file.

	     	r  = readable (- if not)
	     	w  = writeable (- if not)
	     	S  = owner Non Exectuable
	     	s  = owner Exectuable
	     	-  = The file is neither readable, writable, exe-
		     cutable, nor set-user-ID nor set-group-ID mode,
		     nor sticky.
	     	T  = Sticky bit
	     	t  = Sticky Executable

     -m	     Stream output format; list files across the page, separated by
	     commas.

     -n	     Display user and group IDs numerically rather than converting to
	     a user or group name in a long (-l) output.

     -o	     Include the file flags in a long (-l) output.

     -P	     If argument is a symbolic link, list the link itself rather than
	     the object the link references.  This option cancels the -H and
	     -L options.

     -p	     Write a slash (`/') after each filename if that file is a direc-
	     tory.

     -q	     Force printing of non-graphic characters in file names as the
	     character `?'; this is the default when output is to a terminal.

     -R	     Recursively list subdirectories encountered.

     -r	     Reverse the order of the sort to get reverse lexicographical
	     order or the oldest entries first.

     -s	     Display the number of file system blocks actually used by each
	     file, in units of 512 bytes, where partial units are rounded up
	     to the next integer value.	 If the output is to a terminal, a
	     total sum for all the file sizes is output on a line before the
	     listing.  The environment variable BLOCKSIZE overrides the unit
	     size of 512 bytes.

     -T	     When used with the -l (lowercase letter ``ell'') option, display
	     complete time information for the file, including month, day,
	     hour, minute, second, and year.

     -t	     Sort by time modified (most recently modified first) before sort-
	     ing the operands by lexicographical order.

     -u	     Use time of last access, instead of last modification of the file
	     for sorting (-t) or printing (-l).

     -W	     Display whiteouts when scanning directories.

     -w	     Force raw printing of non-printable characters.  This is the
	     default when output is not to a terminal.

     -x	     The same as -C, except that the multi-column output is produced
	     with entries sorted across, rather than down, the columns.

     -v	     Force unedited printing of non-graphic characters; this is the
	     default when output is not to a terminal.

     -1	     (The numeric digit `one'.)  Force output to be one entry per
	     line.  This is the default when output is not to a terminal.

When output to file the files will be listed one per line.

ls-F passes its arguments to ls if it is given any switches, so `alias ls ls-F' generally does the right thing.

EXAMPLES

list the filenames in the current folder
  ls

list the filenames with their characteristics (size, privs, owner, etc)
  ls -l

As above but also including flags (-o option)
  ls -lo

list ALL files (including hidden)
  ls -a

Include a special character at the end that tells you what kind of file it is
  ls -F

list the .jpg files
  ls *.jpg

Filenames beginning with "a"
  ls a*

Filenames containing "att"
  ls *att*

An Apple abbreviation for ls -l 
  l

Another abbreviation, equivalent to ls -la 
 ll

List sorted by Size
   ls -l | sort -n +4

list ALL subdirectories
ls *

Colour Listings

To set up colour labeling, put the following in your ~/.tcshrc file (assuming tcsh is your default OS X shell):
setenv TERM "xterm-color"
setenv CLICOLOR "true"
setenv LSCOLORS "exfxcxdxbxegedabagacad"

Other ls Environment Settings

"If the doors of perception were cleansed every thing would appear to man as it is, infinite" - William Blake

Related commands:

lsbom - List a bill of materials file
quota - Display disk usage and limits
rm - Remove files
rmdir
- Remove folder(s)
wc - Print byte, word, and line counts

Equivalent BASH command:

ls
- List information about FILEs



Back to the Top

Simon Sheppard
SS64.com