Less is More...

less, the GNU utility that resembles the classic UNIX more command, has capabilities you might not be aware of. Sure, it will page through files, but have you ever tried the following?

  less somefile.tar.gz
  less somefile.tar.bz2
  less somefile.zip
  less somepackage.rpm

These commands are equivalent to the following, respectively:

  tar ztvf somefile.tar.gz | less
  tar jtvf somefile.tar.bz2 | less
  unzip -l somefile.zip | less
  (rpm -qpi somepackage.rpm; rpm -qpl somepackage.rpm) | less

In all these cases, less provides the same function with less typing.

The following command is very familiar to Linux and UNIX system administrators:

  tail -f /var/log/messages

For the uninitiated, this command displays the system log (/var/log/messages), and updates the display as new entries are written to the log. For example, you might run a tail -f like the one above on a DHCP server to see DHCP requests and acknowledgments as they happen.

Sometimes, however, you not only want to have the display updated, but you also want to scroll back through the output periodically. less provides this capability. First, less the file that you wish to monitor (this could also be output that has been passed through a pipe to less):

  less /var/log/messages

Now type Shift-f. The display will immediately go to the bottom of the file and you will see a line like the following below the output:

  Waiting for data... (interrupt to abort)

As new data enter the log, the display will update. less will remain in this mode until you type ^c.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Article linked from summersault.com

Here's a trackback to the folks at summersault.com !

Comment