next up previous contents
Next: Changing Current Working Directories Up: Basic Directory Commands Previous: Your Home Directory

Listing a Directory's Contents

To list the contents of a directory use the ls command. The ls command issued alone, without specifying a directory, causes a listing of all subdirectories and non-hidden files in the current working directory to be displayed. By default files are listed in alphabetic order in a series of columns across the screen. Alternative ways of displaying directory contents can be specified by using command-line arguments to the ls command. One reason for providing arguments is that the default listing does not distinguish between subdirectories text files and other special files. To do this, use the -F option of the ls command:

ls -F

The resulting list of files denotes subdirectories with a trailing slash (`/') character, executable programs with a trailing asterisk (`*'), symbolic links with a trailing at-sign (`@'), and sockets with a trailing equals sign (`='). Hidden files, files beginning with a '.', are still not displayed; use the -a argument (for list all files) if you wish to list hidden files as well. To obtain specific information about files and directories, such as mode, size in bytes and time of last modification, use the -l argument with the ls command.

All of the various arguments available for use with any UNIX command can be combined into one character string for all arguments to take effect simultaneously, ie: ls -alFC

Full descriptions for all of the ls flags and options can be found under man ls.

The following aliasesgif are available to make the ls command more friendly:

Pattern matching can be applied to ls, as well as to any other UNIX command. For example, if you wished to list only files that end with the '.c' extension:

ls [-options] *.c

The asterisk 'wildcard' character specifies all filenames. To look for all files with the same name but different extensions, do a listing for <filename>.*.

Listing can be done on directories other than the current one by specifying a path to the directory after the listing options:

ls [-options] tex2html_wrap_inline980 /backup/*.c

This command would give a listing of all files with a .c extension in the subdirectory backup off of your home directory. For more information on Wild Cards see the C Shell Interface section on Wild Cards.


next up previous contents
Next: Changing Current Working Directories Up: Basic Directory Commands Previous: Your Home Directory

Larry Latour
Fri Sep 12 08:12:59 EDT 1997