Previous Table of Contents Next


Module 84
ls

DESCRIPTION

The external ls command lists the contents of a directory. The ls command displays the names of files and directories. Its options allow you to view additional information for each file or directory. The following functions are provided:

*  List filenames and directory names.
*  Display the vital inode information about a file.
*  Recursively list all subdirectories and their contents.
*  Display nonvisual characters of filenames and directory names.
*  Multiple formats provided for output.

COMMAND FORMAT

Following is the general format of the ls command.

       ls [ -1CFLRabcdfgilmnopqrstux ] [ file_list ] [ directory_list ]

BSD (Berkeley)
ls [ -1ACFLRacdfgilqrstu ] [ file_list ] [ directory_list ]

Options

The following list describes the options and their arguments that may be used to control how ls functions.

-1 Display filenames and directories in single-column format. If the output is to a terminal, ls defaults to multicolumn output. If the output is to a file or a pipe, the output is single column by default. You can use the -1 option to override the multicolumn defaults.
-C Lists output in vertically (down the page) sorted columns. The number of columns depends on the length of the longest filename and the screen width.
-F If the file is a directory, a slash (/) is placed after the name. If the file is marked as executable, an asterisk (*) is placed after the name. If the file is a symbolic link, an at sign (@) is placed after the name.
-L If the file or directory is a symbolic link, list the actual file or directory instead of the symbolic link.
-R Recursively lists subdirectories. Each subdirectory that is encountered is listed in the requested format. If you have four levels of subdirectories below your current directory, ls will list all four levels.
-a List all entries including filenames beginning with a period (.). Without this option ls does not list files starting with periods. If you use the -a option with the asterisk (*) filename expansion character, the files beginning with a period will be displayed. Without the -a option they would not be listed.
-b Displays nonvisible characters in an octal format. The \ddd notation is used, where ddd is the octal number representing the ASCII character code.
-c Sorts output based on the time of the last inode modification for each file. Mode change, file created, link added, or time change cause inode changes. Changes how the -t and -l options function. The inode is a header containing file information.
-d If the arguments are directories, list only their names. Suppresses the listing of a directory's contents. Often used with the -l option to list the permissions of directories.
-f Interpret each argument as a directory and list its contents. No sorting is performed. The directory is displayed in the order each file or directory was created and inserted into the directory file. If no arguments are given, the current directory (.) is used. The -l, -r, -s, and -t options are ignored. The -a option is assumed.
-g Same as the -l option, except the owner field is not displayed (group only).
-i Precede each filename with its related inode number.
-l List contents of directory in long format. Displays the modes (see following section), number of links, owner, group, number of bytes, time of last modification, and filename for each entry. If the entry is a special file, then the major and minor numbers are displayed in place of the byte count.
-m Display output in stream format. The files are comma separated across the page with no new-lines inserted.
-n Same as the -l option, except the owner and group fields contain the actual user ID and group ID.
-o Same as the -l option, except the group field is not displayed (owner only).
-p If the file is a directory, a slash (/) is placed after its name.
-q Displays nonvisible characters as question marks (?).
-r Reverse the sorting order.
-s The file size is displayed for each entry. The size is in file system blocks. File system blocks are usually 512, 1024, 2048, or 4096. Indirect blocks are included in this size.
-t Sort entries by time stamp. The default is the last modification time.
-u Sort entries by last access instead of last modification. Use with the -t and -l options.
-x List output in horizontally (across the screen) sorted columns. The number of columns depends on the length of the longest filename and the screen width.
If no options are given, each filename or directory name is listed on a separate line.

BSD (Berkeley)
-A Same as -a (SV) except the . (current directory) and .. (parent directory) entries are not listed.
-C Same as SV. If no options are specified -C is assumed.
-F Same as SV with an additional symbol. If the file is a socket, an equal sign (=) follows it.
-g Includes the group name in the long listing.
-l Same as SV except the group name is not listed.
If no options are given, the -C option is assumed.

Arguments

The following list describes the arguments that may be passed to the ls command.

file_list One or more files ls will search for and attempt to display. Files beginning with a period must be explicitly started with a period or the -a option must be used.
directory_list One or more directories ls will search for and attempt to display. Directories may also begin with a period.
If no arguments are given, ls displays all of the filenames and directory names of the present working directory. The output is sorted alphabetically.


Previous Table of Contents Next