Lesson 2 | More options for listing files |
Objective | List files using the ls command. |
More Options for listing Files using Unix
You already should be familiar with two of the
ls
command’s more useful options:
-l
, which displays the listing in long format
-F
, which flags directory names with a trailing slash (/
).
This lesson will introduce three more
ls
options:
-a
,
-d
, and
-R
.
Listing hidden files
Normally, the ls
command does not display files that start with a dot (.
).
These hidden files typically contain preference settings for certain UNIX commands. If you want to list all files, including hidden files, use ls -a
. Every directory contains at least two hidden files: the .
and ..
directories.
They are shorthand for the current and parent directories respectively. When you specify a relative pathname using .
or ..
, you are referencing these hidden directories.
Listing a directory tree
Directories often contain other directories, which in turn can contain their own subdirectories, and so on down the file hierarchy.
UNIX lets you display a directory tree all at once by using the
ls -R
command. The
-R
option produces a
recursive listing [1]. That is,
ls
descends each subdirectory, listing the contents until the bottom of the hierarchy is reached.
Listing a directory name
Normally, when you specify a directory name with ls
, you see the contents of the directory.
But if you want to display the directory itself, use the -d
option. The following Slide Show shows how to use the -a, -R
, and -d
options.
Advanced Options
Listing Files
In the next lesson, copying directories by using the
-r
option of the
cp
command will be discussed.
[1]
recursive listing: A recursive listing of a directory is one that repeatedly displays all subdirectories down the hierarchy, until the last level of the directory tree is reached.