less is more

Auto Date Wednesday, August 23rd, 2006

Looking at file content is a trivial task, most people use more or less and take there usage for granted. However there are some nice features that these utilities have to offer. Let’s start looking at some of them.

In the following descriptions, ^X means control-X. ESC stands for the ESCAPE key; for example ESC-v means the two character sequence “ESCAPE”, then “v”.

more

More is a filter for paging through text one screen at a time. There are two ways of using more. You can use it from the command line and you can use more in interactive mode.

A nice feature of more is you can make it search for a certain keyword directly from the command line. Lets say we where looking for the word wowbagger in a text file called h2g2.txt we could do.

more +/wowbagger h2g2.txt

This will directly scroll to the first occurrence of wowbagger.

If would like to start reading at line number 50 we could just say.

more +50 h2g2.txt

This would take us to line number 50.

The most important interactive command is h or ? this displays a summary of interactive commands. You can forget all the other commands, just remember this one.

Most people i know use complain about more because they think it cannot skip backwords, however this possible with the b or ^B command. If you would like to know on which line number you are press =, this can give you a quick identification where you are.

Searching for patterns is probably the most import thing you would like todo, searching with more is really easy. Within interactive mode just type / and then the pattern you would like to search. So lets use our h2g2.txt file again.

more h2g2.txt

Now within interactive mode type

/wowbagger

This will scroll you down to the first occurrence of wowbagger. If you would like to search for the next occurrence just press the n command.

Ever happend that you where in the middle of a more session, searching for patterns etc, then all of a sudden you need to type a command in order to look something up. You can do a couple of things. Press q and do the command from the shell, loosing all your work within your more session. Open a new terminal, but if you are like me you probably all ready have a dozen of other terminals open. There is another alternative, say we would like to list the contents in the directory /etc/apache, within interactive mode just do the following

!ls /etc/apache

This will list the contents from the /etc/apache directory in your more session. Sometimes this leave you with the output of your command scrambled through your more text. You can fix this by doing a ^L, this will redraw the screen.

More is great however more is really primitive. That is why most people these days use less which we will get to right now.

Pages: 1 2 3

Bookmark on del.icio.us

Comments are closed.