Why the “less” Command is Better Than “more” in UNIX and Linux

by Aseem Kishore

I work with a lot of huge log files. I usually connect to my UNIX and Linux servers using Putty or Telnet, then I read the files using standard UNIX/Linux commands.  Other IT folks prefer to use an X-window GUI, but if you have a low-bandwidth connection, it is better to use a command line terminal to get things done faster.

If you need to browse logs without having to edit them, use the “less” command.  “Less” in Linux and UNIX lets you view the file and allows you to do basic find operations.  Unlike “more”, it allows for both forward and backward navigation so you can look for any search string at any point in the document.

Table of Contents

    Less Is Better Than More

    To open a file using less,  type the less command followed by the file name in the UNIX or Linux prompt:

    less filename

    In the example below I opened a file called verbose.log.mo

    Less will open the file and display the file name at the lower left portion of the terminal.  To find a string in the file, type forward slash followed by the string that you want to search and then hit Enter.  In the example below, I typed /error to search for the string “error”.

    You will see that the view of the file will jump to the line where the string is located.  The located string matches are highlighted for easier viewing.

    To search for the next instance of the string just press the “n” key.  Pressing the uppercase “N” will bring you to the previous match.

    Here are other keyboard shortcuts I found from Wiki’s entry on “less”:

    What I like most about “less” is that it automatically adjusts with the width and height of the terminal window.  The text when viewed with “less” is automatically wrapped if you resize the window of the terminal.  This makes less more advance than the older tool called “more”, which tends to cut the text as you tighten the width of the terminal.

    If you have a lot of text or ASCII files to view in Linux or UNIX, make sure to master “less” as it is a superior command for viewing files using the command line terminal. Enjoy!

    Exit mobile version