⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0059-0062.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:




<HTML>

<HEAD>

<TITLE>Sams Teach Yourself Linux in 24 Hours:Reading and Navigation Commands:EarthWeb Inc.-</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311623 //-->

<!-- TITLE=Sams Teach Yourself Linux in 24 Hours//-->

<!-- AUTHOR=Bill Ball//-->

<!-- PUBLISHER=Macmillan Computer Publishing//-->

<!-- IMPRINT=Sams//-->

<!-- CHAPTER=04 //-->

<!-- PAGES=0041-0062 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->











<P><CENTER>

<a href="0056-0058.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="../ch05/0063-0065.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-59"><P>Page 59</P></A>





<P>the spacebar, and you can go backward one screenful by tapping the B key.

</P>



<P>The more command also has a number of command-line options. You can customize

the screen prompt (more displays the current percentage of the file you're reading), set the

screen size (the number of lines shown when going forward or backward through your file),

use multiple filenames or wildcards, and turn scrolling on or off, in addition to other options.

</P>



<P>Although you may find the more command to be more than adequate in reading files,

you might really like the less pager.

</P>



<H4><A NAME="ch04_ 18">

Browsing Files with the less Command

</A></H4>



<P>You'll find that less is more or less like more, but you'll also discover that

less is much more than more. Confused? Don't be, because

less, like more, is also a pager command. But its author, Mark Nudelman, has improved on a number of features in the

more command, and added many others.

</P>



<P>The less command offers a number of advantages over

more:

</P>



<UL>

<LI>     You can scroll backwards and forwards through text files using your cursor keys.

<LI>     You can navigate through files with bookmarks, by line numbers, or by

percentage of file.

<LI>     Sophisticated searches, pattern options, and highlighting through multiple files.

<LI>     Compatible keystrokes with word processing programs, such as

emacs.

<LI>     The less command won't quit on you when you reach the end of a file, or the

end of the standard input.

<LI>     The information prompt at the bottom of the screen is more customizable

and offers more information.

<LI>     Loads of options, including a separate key setup program,

lesskey, so you can customize which keys control

less.

</UL>



<P>You'll find that after you install Linux, the

less pager is the default pager used by a number of programs, such as the

man command. And if you need to read compressed files

(those with a .gz extension, and about which you'll learn in Hour 5, &quot;Manipulation and

Searching Commands&quot;), you can use the zless command, found under the

/usr/bin directory.

</P>



<H3><A NAME="ch04_ 19">

Reading the Beginning or End of Files with the

head and tail Commands

</A></H3>



<P>Although the head and tail commands are not pagers per se, they can make life a lot

easier when all you want to do is read the beginning or end of a file. These programs, like

most

</P>







<A NAME="PAGENUM-60"><P>Page 60</P></A>







<P>Linux commands, are designed to do one or two things, but they do these tasks well.

</P>



<P>The head command has a number of options besides the traditional

-n, which prints the first n lines of a file. You'll find that the

head command in your Linux distribution, which is

part of the GNU text utilities, will also print any number of 512-character, 1-kilobyte

(1024 bytes), or megabyte-sized blocks from the beginning of a file. Like the

cat command, head can also handle binary files.

</P>



<P>If you use head in the traditional way, you strip off lines from the beginning of one or

several files. For example, if you'd like to do a quick check of the formatting of all the manual

pages for programs with names beginning with

&quot;xm&quot; under the /usr/man/man1 directory, you can

use the following command:

</P>



<!-- CODE //-->

<PRE>

# head -5 /usr/man/man1/xm*.1

==&gt; /usr/man/man1/xmpeg.1 &lt;==

.TH XMPEG 1 &quot;6 FEBRUARY 1993&quot; &quot;X Version 11&quot;

.SH NAME

xmpeg - X11 MPEG-Player [Version 1.0]

.SH SYNOPSIS

.B xmpeg



==&gt; /usr/man/man1/xmplay.1 &lt;==

.TH XMPLAY 1 &quot;6 FEBRUARY 1993&quot; &quot;X Version 11&quot;

.SH NAME

xmplay - X11 directory browser for xmpeg [Version 1.0]

.SH SYNOPSIS

.B xmplay

</PRE>

<!-- END CODE //-->



<P>Note that the default output from the head command is to include the filename. If

you'd prefer just to have the information, use the

-q option, for example:

</P>



<!-- CODE //-->

<PRE>

# head -5 -q /usr/man/man1/xm*.1

.TH XMPEG 1 &quot;6 FEBRUARY 1993&quot; &quot;X Version 11&quot;

.SH NAME

xmpeg - X11 MPEG-Player [Version 1.0]

.SH SYNOPSIS

.B xmpeg

.TH XMPLAY 1 &quot;6 FEBRUARY 1993&quot; &quot;X Version 11&quot;

.SH NAME

xmplay - X11 directory browser for xmpeg [Version 1.0]

.SH SYNOPSIS

.B xmplay

</PRE>

<!-- END CODE //-->



<P>The tail command is especially useful when you're faced with the task of reading

through large files where the most useful information is at the end of the file. One example task

is if you want to look at the system messages for errors. One message file, located in

/var/log, contains details of system operations, but the log is updated at the end of the message

file (in other words, text is appended, so the most recent messages are at the end of the

file). To look at the last 12 lines in the message file using

tail, make sure you're logged in as root, and type

</P>





<A NAME="PAGENUM-61"><P>Page 61</P></A>







<!-- CODE //-->

<PRE>

# tail -12 /var/log/messages

Nov 12 21:02:02 localhost cardmgr[152]: initializing socket 0

Nov 12 21:02:02 localhost cardmgr[152]: socket 0: ATA/IDE Fixed Disk Card

Nov 12 21:02:02 localhost cardmgr[152]: executing: `insmod /lib/modules/2.0.30/p

cmcia/fixed_cs.o'

Nov 12 21:02:03 localhost kernel: hdc: SunDisk SDCFB-4, 3MB w/1kB Cache, LBA, CH

S=123/2/32

Nov 12 21:02:03 localhost kernel: ide1 at 0x100-0x107,0x10e on irq 3

Nov 12 21:02:03 localhost kernel:  hdc: hdc1

Nov 12 21:02:03 localhost cardmgr[152]: executing: `./fixed start hdc'

Nov 12 21:02:03 localhost cardmgr[152]: initializing socket 1

Nov 12 21:02:03 localhost cardmgr[152]: socket 1: Serial or Modem Card

Nov 12 21:02:03 localhost kernel: tty01 at 0x02f8 (irq = 5) is a 16550A

Nov 12 21:02:03 localhost cardmgr[152]: executing: `insmod /lib/modules/2.0.30/p

cmcia/serial_cs.o'

Nov 12 21:30:17 localhost PAM_pwdb[556]: (su) session opened for user root by bball(uid=0)

</PRE>

<!-- END CODE //-->



<P>Being able to read large files in this way is convenient, considering that the system

messages can grow to more than a million characters.

</P>



<A NAME="PAGENUM-62"><P>Page 62</P></A>







<P><CENTER>

<a href="0056-0058.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="../ch05/0063-0065.html">Next</A>

</CENTER></P>











</td>
</tr>
</table>

<!-- begin footer information -->









</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -