old-www/LDP/GNU-Linux-Tools-Summary/html/text-viewing-tools.html

447 lines
7.0 KiB
HTML
Raw Permalink Blame History

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Text Viewing Tools </TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="GNU/Linux Command-Line Tools Summary"
HREF="index.html"><LINK
REL="UP"
TITLE="Text Related Tools"
HREF="text-related-tools.html"><LINK
REL="PREVIOUS"
TITLE="Text Editors"
HREF="text-editors.html"><LINK
REL="NEXT"
TITLE="Text Information Tools"
HREF="text-information-tools.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>GNU/Linux Command-Line Tools Summary</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="text-editors.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 11. Text Related Tools</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="text-information-tools.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="TEXT-VIEWING-TOOLS"
></A
>11.2. Text Viewing Tools</H1
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>head</DT
><DD
><P
>With no options it shows the first ten lines of a text file. </P
><P
>Use<EM
> head -n x </EM
>(where &#8220;x&#8221; is a number) to display the first x<EM
> </EM
>lines. </P
><P
>Try <EM
> head -F </EM
>to use a continually updated version of <EM
>head</EM
> (if the file changes it will be reloaded and displayed), please note that using this option will run <EM
>head</EM
> is a continuous loop so you'll need to use
<B
CLASS="KEYCAP"
>CTRL</B
>-<B
CLASS="KEYCAP"
>C</B
>
to exit.</P
><P
>For example:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>head -n 20 somelog.txt </PRE
></FONT
></TD
></TR
></TABLE
><P
>Will display the top 20 entries of the file &#8220;somelog.txt&#8221;.</P
></DD
><DT
>tail</DT
><DD
><P
>With no options it shows the last ten lines of a file. </P
><P
>Use<EM
> tail -n x </EM
>(where &#8220;x&#8221; is a number) to display the last <EM
>x </EM
>lines. </P
><P
>Try<EM
> tail -F </EM
>to use a continually updated version of <EM
>tail</EM
> (if the file changes it will be reloaded and displayed), please note that using this option will run <EM
>tail</EM
> is a continuous loop so you'll need to use
<B
CLASS="KEYCAP"
>CTRL</B
>-<B
CLASS="KEYCAP"
>C</B
>
to exit.</P
><P
>For example:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>tail -n 20 somelog.txt</PRE
></FONT
></TD
></TR
></TABLE
><P
>Will display the last 20 entries of the file &#8220;somelog.txt&#8221;.</P
></DD
><DT
>less</DT
><DD
><P
>Views text, can scroll backwards and forwards. Has many different options which are all described in the manual page. </P
><P
>When <EM
>less</EM
> is already running, use :n and :p (type a colon then the character) to move to the next and previous files (when there are multiple open files).</P
><P
>Command syntax:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>less filename.txt</PRE
></FONT
></TD
></TR
></TABLE
><P
>Or using a tool (in this example <EM
>cat</EM
>):</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>cat file.txt | less</PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>more</DT
><DD
><P
>Displays text, one page full at a time, more limited than <EM
>less</EM
>. In this case <EM
>less</EM
> is better than <EM
>more</EM
>.</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>more filename.txt</PRE
></FONT
></TD
></TR
></TABLE
><P
>Or using a tool (is this example cat):</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>cat file.txt | more</PRE
></FONT
></TD
></TR
></TABLE
></DD
><DT
>cat<A
NAME="CAT"
></A
></DT
><DD
><P
>Combines (concatenates) multiple documents into one document. Can be used on individual files as well.</P
><P
>Some useful options:</P
><P
></P
><UL
><LI
><P
><EM
>-b</EM
> --- number all non-blank lines</P
></LI
><LI
><P
><EM
>-n</EM
> --- number all lines. </P
></LI
></UL
><P
>Also try using <EM
>nl</EM
> to number lines (it can do more complex numbering), you will find it under under this section, <A
HREF="text-manipulation-tools.html"
>Section 11.4</A
></P
><P
>Example:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>cat filepart1 filepart2 filepart3 &#62; wholefile.txt</PRE
></FONT
></TD
></TR
></TABLE
><P
>This will combine (concatenate) filepart1, filepart2 and filepart3 into the single file &#8220;wholefile.txt&#8221;.</P
></DD
><DT
>tac</DT
><DD
><P
>Combines (concatenates) multiple documents into one document and outputs them in reverse order. Can also be used on individual files. Notice that <EM
>tac</EM
> is <EM
>cat</EM
> written backwards. </P
><P
>Example:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>tac filepart1 filepart2 filepart3 &#62; wholefile.txt</PRE
></FONT
></TD
></TR
></TABLE
><P
>This will combine (concatenate) filepart1, filepart2 and filepart3 into the single file but have each of the files written in reverse.</P
></DD
><DT
>z*<2A>commands</DT
><DD
><P
>Many commands can be prefixed with a &#8220;z&#8221; to read/work within a gzip compressed file. </P
><P
>Some examples are <EM
>zcat, zless, zmore, zgrep, zcmp, zdiff</EM
>. </P
><P
>There are many utilities for working with text within compressed files without trying to manually de-compress them somewhere first...most begin with a &#8220;z&#8221;. You will find some of them mentioned over here, <A
HREF="compression.html"
>Section 15.3</A
>.</P
></DD
><DT
>bz*<2A>commands</DT
><DD
><P
>There are also a few commands that prefixed with a &#8220;bz&#8221; to read/work within a file compressed with bzip2. </P
><P
>The tools are <EM
>bzcat, bzless, bzgrep.</EM
> You will find some of them mentioned over here, <A
HREF="compression.html"
>Section 15.3</A
>.</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="text-editors.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="text-information-tools.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Text Editors</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="text-related-tools.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Text Information Tools</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>