You know how to get a list of files. But what if you want to take a peek at a file's contents? Several commands, including cat,
more, and less, can be used to display files. Let's see how they work in this example:
$ cat pig_info
Pigs make great pets, but they are not dogs or cats. Maybe
somewhere in between. I tend to believe that they have more
personality. They do require significant amounts of attention,
love, and scratches. But they aren't always snuggly in return.
The cat command (short for concatenate) shown in this example is like the DOS type command. In response to the command cat pig_info, the system simply splatters the file on the screen. If there is more data in the file than will fit on one screen, the contents whiz by before you can see it. The more command solves this problem by displaying the file screen by screen:
$ more dog_info
Affectionately known as the "Toller," the Nova Scotian Duck
Tolling Retriever was once called the Little River Duck Dog,
since it was developed in the Little River district of Yarmouth
County, Nova Scotia. This engaging dog is a specialist with
waterfowl. Tolling, or luring, is the practice of tricking ducks
into gunshot range. Hunters had long observed this behavior
--More--(01%)
The more command pauses when the screen fills up and waits for you to press the spacebar before it rolls out another screenful of text. A legend at the bottom of the screen tells you what percentage of the file has been displayed so far.
The less command works like more except that it lets you move both forward and backward in the file while the command is running--use the B key on your keyboard to back up one screen and the spacebar to move forward and show the next screen.
You can press Q to quit the more or less command.
Although all of these commands will let you view the contents of a file in different ways, none allow you to change the data in the file. If you want to view and update a file, use one of the text editors discussed in the "Text Editors" section.
For more information on the cat command, see the cat manual. (If you're not interested in cats, see the dog manual.)
Previous Lesson: Listing Linux Files
Next Lesson: Copying and Renaming Files
Popular Linux Topics
Linux IntroLinux Tutorial
Who is Doctor Bob?Linux Basics
Living in a ShellLinux Files
The Linux File SystemLinux Commands
Important Linux CommandsLinux Editors
The Vi EditorLinux Data Manipulation
Slicing & DicingLinux Shell Programming
Linux Shell ScriptsPerl Programming
Perl BasicsLinux and Email
Sending EmailCompression and Encoding
Linux File CompressionLinux Does DOS
Accesing DOS FilesManaging Linux
Updating Your Linux System