cat, more, less, and tail
There’s several very basic ways to read files within linux. The 4 most important are cat, more, less, and tail. After this tutorial you might want to check out the following tutorials:.
The cat Command
The cat program used to command is a standard Unix concatenate and display files. The name is from catenate, a synonym of concatenate. More and less are simple ways to scroll through programs, while tail will display the last number of lines within a file that you specify. After this tutorial you might consider following it up with these other tutorials:
cat’s general syntax is: cat [options] [filenames] [-] [filenames]
The most common use of cat is to read the contents of files, and cat is often the most convenient program for this purpose. All that is necessary to open a text file for viewing on the display monitor is to type the word cat followed by a space and the name of the file and then press the ENTER key. For example, the following will display the contents of a file named file1.txt:
cat file1.txt
The second role of cat is concatenation (i.e., stringing together) of copies of the contents of files. (This is the source of cat’s curious name.) Because the concatenation occurs only to the copies, there is no effect on the original files.
For example, the following command will concatenate copies of the contents of the three files file1.txt, file2.txt and file3.txt:
cat file1.txt file2.txt file3.txt
The contents of each file will be displayed on the monitor screen (which, again, is standard output, and thus the destination of the output in the absence of redirection) starting on a new line and in the order that the file names appear in the command.
The more command
more is a program on Unix and Unix-like systems used to view (but not modify) the contents of a text file one screen at a time. Programs of this sort are called pagers. more is a very basic pager, originally allowing only forward navigation through a file, though newer implementations do allow for limited backward movement.
The general usage of more would be:
more file1.txt
If file1.txt has more than 1 screen worth of data within it, the more command allows you to view one screen at a time. Unlike cat which prints the whole file to the screen, you can use the enter button to scoll down through the file.
The less command
Much like the more command, less allows information to be read more easily than cat. Where as the more command lets you see one screen at a time, less allows you to scroll one line at a time. Test it out:
less file1.txt
The tail command
The tail command behaves a bit differently. It allows you to specify the number of lines at the end of a file you wish to see. For instance if you wish to see the last 10 lines of the file1.txt file you would type
tail -10 file1.txt
The number 10 can be changed to whatever value you like.