Why the “less” Command is Better Than “more” in UNIX and Linux
Plus handy keyboard shortcuts to use
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.
Less Is Better Than More
To open a file usingless, type thelesscommand followed by the file name in the UNIX or Linux prompt:
less filename
In the example below I opened a file calledverbose.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/errorto 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 fromWiki’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!
Founder of Help Desk Geek and managing editor. He began blogging in 2007 and quit his job in 2010 to blog full-time. He has over 15 years of industry experience in IT and holds several technical certifications.Read Aseem’s Full Bio
Leave a Reply
Your email address will not be published.Required fields are marked*
Comment*
Name*
Email*
Website
Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.
HomeAbout UsEditorial StandardsContact UsTerms of Use
Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved