(13 ratings)   
By: tuxfiles.org
Many files on a Linux system are files that are human readable and can be viewed as text. For example, shell scripts are just simple text files, as well as many of the important configuration files that can be edited by hand. This is why Linux...
Added: 13 May 2008    Views: 1173  
Keywords: computer   operating   system   linux   general   help   compile   unix   administration   view   text   files  
Do you like this tutorial? Now you can support our team to add more :     
 
 
 

< Viewing text files with cat >

Many files on a Linux system are files that are human readable and can be viewed as text. For example, shell scripts are just simple text files, as well as many of the important configuration files that can be edited by hand. This is why Linux provides many ways of editing and viewing text files, but here I'll concentrate on cat and less.

cat is a simple little program that displays the contents of a text file when you give the file name as an argument to it:
$ cat view_this

This is a nice way of viewing short files that fit on your screen, but if the file is so long that its contents cannot be displayed on your screen all at once, you'll end up only staring at the end of the file. Maybe not exactly what you want. In most cases, you'll want to use less instead.


< Using the less command >

less is a program that lets you view text files, like cat does, but if the files are so long that they don't fit on your screen, less automatically paginates the file. You use less by giving the file name as an argument to it:
$ less view_this

When viewing the file, you can use Page Up and Page Down keys to move through the file, and typing q will exit.

You can also open several files at the same time so you can navigate from one file to next without closing it first. If you want to open several files, just give all the file names at once:
$ less file1 file2 file3

When viewing several files at the same time, you can use :n for examining the next file and :p for the previous file.

Here are some, but absolutely not all, of the commands you can use in less:

Command / key Action
e, j, Down, or Enter move forward one line
y, k, or Up move backward one line
f, Space, or Page Down move forward one page
b, or Page Up move backward one page
/characters search forward in the file for lines containing the specified characters
n repeat the previous search
:e file_name examine a new file
:n examine the next file
:p examine the previous file
h, or ? display help
q quit
About the Author :
How to view text files in Linux
Articles and Tutorials Directory by www.learnfobia.com
 Rate this tutorial : Rate 1Rate 2Rate 3Rate 4Rate 5
  |    Add to Favorites
  |    Send to Friend
  |    Print
Comments