Listing contents of other directories, Flags used with the ls command, The ls command flags – HP NonStop G-Series User Manual

Page 94

Advertising
background image

You can also list individual files and subdirectories in your current directory using the command
format:

ls filename

The filename entry can be the name of a file or a list of filenames separated by spaces. You
can also use pattern-matching characters to specify files. See

Chapter 3 (page 31)

, for information

on pattern matching.

For example, to list the files whose names begin with the characters “file,” you would enter the
following command:

$ ls file*

file1 file2 file3

Listing Contents of Other Directories

To display a listing of the contents of a directory other than your current directory, use the following
command:

ls dirname

The dirname entry is the pathname of the directory whose contents you want to display.

The ls command ordinarily lists directory and filenames in collated order as determined by the
current locale.

Flags Used With the ls Command

In its simplest form, the ls command displays only the names of files and directories contained in
the specified directory. However, ls has several flags that provide additional information about
the listed items or that change the way in which the listing is displayed.

When you want to include flags with the ls command, use the following format:

ls -flagname

The -flagname entry specifies one or more flags (options) that you are using with the command.
For example, the -l flag produces a long listing of the directory contents. Note also that all flags
are preceded by the - (hyphen) character.

If you want to use multiple flags with the ls command, enter the flag names together in one string,
such as:

$ ls -ltr

Table 14

lists some of the most useful ls command flags.

Table 14 The ls Command Flags

Description

Flag

Lists by name order in long format. A -l listing provides the type, permissions, number of
links, owner, group, size, and time of last modification for each file or directory listed.

-l

Sorts the files and directories by the time they were last modified (latest first), rather than
by name.

-t

Sorts the files and directories in reverse order. When the -r flag is combined with the -t
flag, the files and directories are sorted by the time of last modification with the earliest
first.

-r

Lists all entries, including hidden files. Without this flag, the ls command does not list the
names of entries that begin with a . (dot), such as the .profile file and relative
pathnames.

-a

Specifies that the /G directory or /E directory should be omitted when the initial directory
is the root directory and the recursive flag (-R) is used. This flag is ignored when the initial

-W NOG, -W NOE

directory is not /, /E, /E/system or when recursion does not occur. See

Chapter 5

(page 68)

, for more information on recursive operations.

94

Managing Files

Advertising
This manual is related to the following products: