Now that you know how to change directories, it's time to take a look at what's
in these directories.
Type ls and press [Enter]. You should see
the contents of your current directory — or most of it, at least.
The ls command, by itself, won't show you all the
files in your directory. To see everything, you must include another
option or two.
A multitude of options are available with the ls
command.
 | Read the ls Man Page |
|---|
| | If you want to see all the options of the ls
command, you can read the man page by typing man
ls at a shell prompt. If you want to print the man page,
type man ls | col -b | lpr at the prompt.
|
Why are there so many options? Because they can help you sort
information according to your needs. For example, you can specify how
files are displayed, see their permissions and much more.
Type ls -a. Now you'll see files that begin with
dots. These are called hidden files or, appropriately enough, dot files.
Hidden files are mostly configuration files which set preferences in
programs, window managers, shells, and more. The reason they're hidden
is to help prevent any accidental tampering by the user. Besides, when
you're searching for something in a directory, you're not usually
looking for these configuration files, so keeping them hidden helps to
avoid some screen clutter.
Viewing all the files (ls -a) can give you plenty
of detail, but you can view still more information, simply by adding
more than one option.
If you want to see the size of a file or directory, when it was created
and more, just add the "long" option (-l) to the
ls -a command:
This command shows the file creation date, its size, ownership,
permissions, and more.
You don't have to be in the directory whose contents you want to view to
use the ls command.
See what's in the /etc directory by typing:
You'll get plenty of information about the contents of the
/etc directory.
Here's a short list of some popular options with
ls. Remember, you can view the full list by
reading the ls man page (man
ls).
-a — all. Lists all the files in the
directory, including the hidden files
(.filename). The .. and
. at the top of your list refer to the parent
directory and the current directory, respectively.
-l — long. Lists details about
contents, including permissions (modes), owner, group, size,
creation date, whether the file is a link to somewhere else on the
system and where its link points.
-F — file type. Adds a symbol to the
end of each listing. These symbols include
/ to indicate a directory;
@ to indicate a symbolic link to
another file; and * to indicate an
executable file.
-r — reverse. Lists the contents of the
directory from back to front.
-R — recursive. This recursive option
lists the contents of all directories (below the current directory)
recursively.
-S — size. Sorts files by their size.
A little later in this chapter, when we introduce you to pipes and I/O
redirection, you'll discover that there are other ways to view the
contents of a directory.