| Red Hat Enterprise Linux 4: Red Hat Enterprise Linux Step By Step Guide | ||
|---|---|---|
| Prev | Chapter 4. Shell Prompt Basics | Next | 
Red Hat Enterprise Linux has several applications that allow you to view and manipulate text files at the shell prompt. These applications are fast and best suited to manipulating the plain text files of configuration files.
The head command displays the beginning of a file. The format of the head command is:
| head <filename> | 
By default, you can only read the first ten lines of a file. You can change the number of lines displayed by specifying a number option.
| head -20 <filename> | 
The above command would display the first 20 lines of a file named <filename>.
The reverse of head is tail. Using tail, you can view the last ten lines of a file. This can be useful for viewing the last ten lines of a log file for important system messages. You can also use tail to watch log files as they are updated. Using the -f option, tail automatically prints new messages from an open file to the screen in real-time. For example, to actively watch /var/log/messages, enter the folowing at a shell prompt (as the root user):
| tail -f /var/log/messages | 
	Press
	
The more command is a "pager"
	utility used to view text in the terminal window one page or
	screen at a time. The 
The format of the less command is:
| less <filename> | 
 The main difference between more and
	less is that less allows
	backward and single-line movement using the same navigation as
	man pages: press the 
To search the output of a text file using
	less, press 
| /stuff | 
The above command would search through the file for all instances of "stuff" and highlight them in the text.
The cat command is a versatile utility. It can be used to view text, to create text files, and to join files. Its name is short for concatenate, which means to combine files.
Using cat alone echoes on the screen
	any text you enter.  It will continue to do so until you exit
	with the
	
Entering the cat command followed by a file name displays the entire contents of the file on the screen. If the file is long, the contents scroll off the screen. You can control this by using the redirection techiniques that are discussed in Section 4.9 Manipulating Information from the Shell.
The grep command is useful for finding specific character strings in a file. For example, to find every reference made to "pattern" in the file <filename>, enter:
| grep pattern <filename> | 
Each line in the file that includes the pattern "pattern" is located and displayed on the screen/