Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

11.2. Text Viewing Tools

head With no options it shows the first ten lines of a text file.

Use head -n x (where "x" is a number) to display the first x lines.

Try head -F to use a continually updated version of head (if the file changes it will be reloaded and displayed), please note that using this option will run head is a continuous loop so you'll need to use CTRL-C to exit.

For example:

head -n 20 somelog.txt 

Will display the top 20 entries of the file "somelog.txt".

tail With no options it shows the last ten lines of a file.

Use tail -n x (where "x" is a number) to display the last x lines.

Try tail -F to use a continually updated version of tail (if the file changes it will be reloaded and displayed), please note that using this option will run tail is a continuous loop so you'll need to use CTRL-C to exit.

For example:

tail -n 20 somelog.txt

Will display the last 20 entries of the file "somelog.txt".

less Views text, can scroll backwards and forwards. Has many different options which are all described in the manual page.

When less 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).

Command syntax:

less filename.txt

Or using a tool (in this example cat):

cat file.txt | less
more

Displays text, one page full at a time, more limited than less. In this case less is better than more.

more filename.txt

Or using a tool (is this example cat):

cat file.txt | more
cat

Combines (concatenates) multiple documents into one document. Can be used on individual files as well.

Some useful options:

  • -b --- number all non-blank lines

  • -n --- number all lines.

Also try using nl to number lines (it can do more complex numbering), find it under under this section, Section 11.4

Example:

cat filepart1 filepart2 filepart3 > wholefile.txt

Would combine (concatenate) filepart1, filepart2 and filepart3 into the single file "wholefile.txt".

tac Combines (concatenates) multiple documents into one document and outputs them in reverse. Can also be used on individual files. Notice that tac is cat written backwards.

Example:

tac filepart1 filepart2 filepart3 > wholefile.txt

Would combine (concatenate) filepart1, filepart2 and filepart3 into the single file but have each of the files written in reverse.

z* commands

Many commands can be prefixed with a "z" to read/work within a gzip compressed file.

Some examples are zcat, zless, zmore, zgrep, zcmp, zdiff.

There are many utilities for working with text within compressed files without trying to manually de-compress them somewhere first...most begin with a "z".

bz* commands

There are also a few commands that prefixed with a "bz" to read/work within a file compressed with bzip2.

The tools are bzcat, bzless, bzgrep

 
 
  Published under the terms of the GNU General Public License Design by Interspire