- ThinkBlog - http://thinkblog.org -
Linux Tip 005 - “more” or “less”
Posted By Michael On 13th November 2003 @ 01:14 In Linux | No Comments
When you’re at a Linux (or UNIX) command line, there are several ways to view a text file without having to open up an actual text editor. One of the most commonly-employed options is “cat”, a program designed to concatenate two or more files together that can also be used to display a byte stream (like a text file, or any other kind of file for that matter!) in text on a terminal. Alternately, the output text of cat can be piped through to another program that acts on that input. There’s no way to stop the flow of text, though, so if you’re reading a text file that’s more than a little under two kilobytes (2KB), this isn’t the best option. Another program is tail, which takes the last ten (10) lines (or, using the -n switch, whatever number you specify) of a text file and prints them out. While this is useful for manually scanning through a large file like /var/log/messages and looking for minutewise changes and other such applications, that’s not suitable for everything either. The most popular choices fall to two applications: more and less, the latter of which is a word play on the former. Neither less nor more read in an entire text file all at once, so if you’re so inclined, you can load up a plain-text copy of Shakespeare’s complete works and read it line for line without worrying about the fact that it won’t all fit into your small bit of RAM.
The “more” program takes a text file, reading it in line-by-line, and prints it to the console (the screen of the command line). It can step through a file on a per-line basis, or on a per-screen basis, but you can’t move back and forth within a file. Furthermore, the types of terminals that more can run on are somewhat limited because of its simplicity.
“less” picks up where more fails, allowing backward as well as forward movement within a file (you can scroll up or down), and there is support for a wide variety of terminals, even limited hardcopy terminal support.1 Furthermore, with `more’, when a ^D is reached (End of File, or EOF character, remember?), the program will “bottom out”—it will terminate, having come to the end of the file! If, for some reason, there are multiple ^D characters, this can perhaps cause you to log out of your terminal (if, for instance, you’re using bash and $IGNOREEOF is set to 0). “less” is not affected by these issues.
Thus, in this case, it can be said (as it has been2!), “less” is more!
[1] A hardcopy terminal is one that prints to (usually) paper, as opposed to a video terminal which prints to a monitor screen. Obviously, Shakespeare’s complete works would be an obnoxious thing to browse on a hardcopy terminal.
[2] mRgOBLIN, on the hh-unix Yahoo! Group, 24 April 2003.
Linux Tip 005 - “more” or “less”
Posted By Michael On 13th November 2003 @ 01:14 In Linux | No Comments
When you’re at a Linux (or UNIX) command line, there are several ways to view a text file without having to open up an actual text editor. One of the most commonly-employed options is “cat”, a program designed to concatenate two or more files together that can also be used to display a byte stream (like a text file, or any other kind of file for that matter!) in text on a terminal. Alternately, the output text of cat can be piped through to another program that acts on that input. There’s no way to stop the flow of text, though, so if you’re reading a text file that’s more than a little under two kilobytes (2KB), this isn’t the best option. Another program is tail, which takes the last ten (10) lines (or, using the -n switch, whatever number you specify) of a text file and prints them out. While this is useful for manually scanning through a large file like /var/log/messages and looking for minutewise changes and other such applications, that’s not suitable for everything either. The most popular choices fall to two applications: more and less, the latter of which is a word play on the former. Neither less nor more read in an entire text file all at once, so if you’re so inclined, you can load up a plain-text copy of Shakespeare’s complete works and read it line for line without worrying about the fact that it won’t all fit into your small bit of RAM.
The “more” program takes a text file, reading it in line-by-line, and prints it to the console (the screen of the command line). It can step through a file on a per-line basis, or on a per-screen basis, but you can’t move back and forth within a file. Furthermore, the types of terminals that more can run on are somewhat limited because of its simplicity.
“less” picks up where more fails, allowing backward as well as forward movement within a file (you can scroll up or down), and there is support for a wide variety of terminals, even limited hardcopy terminal support.1 Furthermore, with `more’, when a ^D is reached (End of File, or EOF character, remember?), the program will “bottom out”—it will terminate, having come to the end of the file! If, for some reason, there are multiple ^D characters, this can perhaps cause you to log out of your terminal (if, for instance, you’re using bash and $IGNOREEOF is set to 0). “less” is not affected by these issues.
Thus, in this case, it can be said (as it has been2!), “less” is more!
[1] A hardcopy terminal is one that prints to (usually) paper, as opposed to a video terminal which prints to a monitor screen. Obviously, Shakespeare’s complete works would be an obnoxious thing to browse on a hardcopy terminal.
[2] mRgOBLIN, on the hh-unix Yahoo! Group, 24 April 2003.
Article printed from ThinkBlog: http://thinkblog.org
URL to article: http://thinkblog.org/2003/11/13/linux_tip_005_more_or_less/
Click here to print.