Displaying Linux Files

Discuss everything about Linux here!

Moderator: Community Moderator

Post Reply
User avatar
MrNiitriiX
Premium Uploader
Premium Uploader
Posts: 2197
Joined: 19 Apr 2010, 14:52
Location: between space and time
Has thanked: 24 times
Been thanked: 164 times

Displaying Linux Files

Post by MrNiitriiX »

How Do I Display the Contents of a Linux File?

Displaying File Contents

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. You can press ctrl-C to quit more before reaching the end of the file.

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.
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.

Leason 1: The Linux File System
Leason 2: Linux File Names
Leason 3: Linux Directories
Leason 4: Directory Terminology
Leason 5: Navigating the File System
Leason 6: Listing Linux Files
Leason 7: Displaying Linux Files
Leason 8: Copying and Renaming Files
Leason 9: Creating Files and Directories
Leason 10: Deleting Files and Directories
Leason 11: Linux Files - Wildcards
Leason 12: The Nine Deadly Keystrokes
Leason 13: Linux File Permissions
Leason 14: Changing File Permissions
Last edited by MrNiitriiX on 30 Sep 2010, 14:59, edited 1 time in total.
"Injustice anywhere is a threat to justice everywhere." - Martin Luther King
Image
Upload List
Post Reply

Return to “Everything Linux”