Linux Classes
Share This With a Friend  
LINUX CLASSES - FILES

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.

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

[ RETURN TO INDEX ]


   

Comments - most recent first
(Please feel free to answer questions posted by others!)

Michael     (27 Aug 2013, 21:42)
Hi,
How do you display the contents of a file in real time on Linux please?
inetryconydot     (02 Aug 2013, 20:35)
Hello! I really liked your forum, especially this section. I just signed up and immediately decided to introduce myself, if I'm wrong section, ask the moderators to move the topic to the right place, hopefully it will take me well... My name is Viktor, me 34 years, humourist and serious man in one person. Ssory for my English.
Bob Rankin     (27 Feb 2012, 16:27)
@Ramy - Press q to end the less or more command.
Ramy Al Zuhouri     (27 Feb 2012, 15:10)
A problem is that when I use less command to display a file, when I reach the end a line appears: "END", and I can't use the terminal tab to type other commands.I have to open a new tab.
There's a way to break? Neither with ctrl-c works.
santosh ahirwar     (05 Feb 2012, 14:45)
Hi bob,
Thanks its short and understandable notes for
new in linux and want to learn. Nice job for us.
i give you thank from all who use this site.
:-)
Emo LeBlanc     (15 Jan 2012, 17:10)
Bob, Thank you for putting in the hard work, time, and effort. I want you to know that it is greatly appreciated. Comprehension is awesome and should ever put out a book please notify me and I will put my money where my mouth is and purchase it !
Once again Thank you.
Emo LeBlanc
Sanika     (10 Jul 2011, 23:23)
Awesome site!!Linux is great and u have written a lovely site for it.Easy to understand.Keep the good work.
Deepak Parihar     (11 Mar 2011, 01:20)
This site helped me a lot. Thanks for nice documentation. Keep doing good work.
vetrivel     (11 Feb 2011, 01:13)
hi bob,
I want to know how to access the bin directory and can you briefly explain how to remove files from bin directory and what are all commands used to view the bin directories.

Thanks,
vetri
shahid iqbal     (24 Nov 2010, 08:30)
i want to display the content of my flash drive through linux fedora command .so what is the command for this , thank u
A. Raskin     (21 Sep 2010, 04:36)
Thanks for helpful site!
Bob Rankin     (02 Jun 2010, 06:42)
Look for the Linux Editors section to your left.
Michelle     (02 Jun 2010, 00:46)
where's the text editor?
Bob Rankin     (18 Mar 2010, 20:50)
Sorry, it's only available on the website.
Milton     (18 Mar 2010, 15:19)
Hello Bob, IŽam from venezuela and I want to ask you if you have your low fat linux paper in pdf format and if is possible, that can I have it?
In advance tanks

I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But don't ask me to send what you already have. :-)

NO SPAM! If you post garbage, it will be deleted, and you will be banned.
*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 
 


Ask Bob Rankin - Free Tech Support


Copyright © by - Privacy Policy
All rights reserved - Redistribution is allowed only with permission.