If you have a text file in Linux that you want to view but you don’t need to make changes to it, you can use the cat and less commands.
Viewing Short Text Files with the cat Command
If you have a short file you want to view that will fit on the screen, use the cat command as follows:
$ cat <filename>
The cat command is good for files that are not longer than the display area of the current Terminal window, and, therefore, do not require scrolling.
Using the less Command to View Longer Files
If the file is so long that the contents cannot all be displayed in your Terminal window at once, use the less command.
$ less <filename>
It works like the cat command; however, if the file is longer than the Terminal window less automatically paginates the file.
When viewing the file, use the Page Up and Page Down keys to move through the file. To close the file, type q.
You can open several files at the same time and navigate among the files without having to close one and open the next file. Just give less the names of all the files you want to open.
$ less <filename1> <filename2> <filename3>
To move from one file to the next file, press :n. To go to the previous file, press :p.
NOTE: When you open multiple files, typing q closes all files at once.
The following table lists some of the common commands available 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 filename | Examine a new file |
| :n | Examine the next file |
| :p | Examine the previous file |
| h or ? | Display help |
| q | Quit |
Remember that cat and less do not allow you to edit files, only view their contents. There are text editors available, such as gedit, for editing text files.
by Lori Kaufman















can't you do a vi command also?
Yes, you can open a text file using vi, but, if all you want to do is view a text file, the cat command will display the text file and bring you back to the prompt immediately. It's not much quicker, but it is a little easier.
[...] If this list is very long, it will scroll off the end of the Terminal window. Therefore, we should use the less command so we can view the list page by page. For more information about the less command, see View Text Files Quickly in Linux. [...]