Java Reference
In-Depth Information
for your input. You can press the space bar to get the next screen's worth of
output. You can type a slash, then a string, and it will search forward for that
string. If you have gone farther forward in the file than you wanted, press “
b
”
to go backwards.
To find out more about the many, many commands available, press
?
(the question mark) while it's running.
Typical uses for these commands are:
• To view one or more files, for example
more *.java
, where you can type
:n
to skip to the next file.
• To page through long output from a previous pipe of commands, for ex-
ample,
$ grep Account *.java | more
, which will search (see more
on
grep
below) for the string
Account
in all of the files whose names end
in
.java
and print out each line that is found—and that output will be
paginated by
more
.
If you need only to check the top few lines of a file, use
head
. You can
choose how many lines from the front of the file to see with a simple parameter.
The command
head -7
will write out the first seven lines, then exit.
If your interest is the last few lines of a file, use
tail
. You can choose how
many lines from the end of the file to see; the command
tail -7
will write
out the last seven lines of the file. But
tail
has another interesting parameter,
-f
. Though
tail
normally prints its lines and then, having reached the end of
file, it quits, the
-f
option tells
tail
to wait after it prints the last few lines and
then try again.
7
If some other program is writing to this file, then
tail
will, on
its next read, find more data and print it out. It's a great way to watch a log file,
for example,
tail -f /tmp/server.log
.
In this mode,
tail
won't end when it reaches the end of file, so when you
want it to stop you'll have to manually interrupt it with a
^C
(Control-C— i.e.,
hold down the Control key and press the C key).
disclosure, there is also a paging program called
pg
, the precursor to
more
, but we'll say no
more about that.
7. The
less
command has the same feature. If you press “F” while looking at a file, it goes into
an identical mode to the
tail -f
command. As is often the case in the wacky world of Linux,
there is more than one way to do it.