![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Complete Idiot's Guide to Linux
Viewing a Page at a Time: lessWhen you use cat, you might have already found out that if the size of the file is more than can fit on your screen, the contents scroll much too fast for you to read. One way of handling this is by using a pager command. Pagers allow you to view a screenful (or page) of information at a time. There are two commands that you can use: the original pager called more and the better pager less. In the case of these programs, less is actually more. For example, less allows you to back up and scroll up something that more doesnt allow. less also doesnt quit until you tell it to. When less prints a screenful, it puts at the bottom of the screen a colon (:). This means that theres more information after the current page. While the colon is displayed, you can interact with less and send it commands. Here are some of the more useful:
When you reach the end of the file, less aptly prints END at the bottom of the screen; press Q if you would like to exit the program. Peeking at the First Few Lines: headSometimes you dont want to read an entire file, just the first few lines. The command for this is called head, and it prints the first ten lines in a file: [alberto@digital alberto]$ head /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin: daemon:x:2:2:daemon:/sbin: adm:x:3:4:adm:/var/adm: lp:x:4:7:lp:/var/spool/lpd: sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:11:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail: news:x:9:13:news:/var/spool/news: If you pass the -n option, you can control how many lines head prints: [alberto@digital alberto]$ head -n 1 /etc/passwd root:x:0:0:root:/root:/bin/bash Peeking at the Last Few Lines: tailThe flip side to head is tail. By default it prints the last ten lines. If you supply the -n option, head will print that number of lines from the end of the file: [alberto@digital alberto]$ tail -n 1 /etc/passwd alberto:x:100:100:Alberto Ricart:/home/alberto:/bin/bash
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |