{"id":12131,"date":"2019-03-22T11:30:09","date_gmt":"2019-03-22T11:30:09","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12131"},"modified":"2019-03-22T11:30:09","modified_gmt":"2019-03-22T11:30:09","slug":"learn-why-less-is-faster-than-more-command-for-effective-file-navigation","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/learn-why-less-is-faster-than-more-command-for-effective-file-navigation\/","title":{"rendered":"Learn Why \u2018less\u2019 is Faster Than \u2018more\u2019 Command for Effective File Navigation"},"content":{"rendered":"<p><strong>More<\/strong>\u00a0is a *nix command line used to display the contents of a file in a console. The basic usage of\u00a0<strong>more<\/strong>command is to run the command against a file as shown below:<\/p>\n<p><b>Read Also:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/learn-linux-cat-command-and-tac-command\/\" target=\"_blank\" rel=\"noopener\">Learn Difference Between \u2018cat\u2019 and \u2018tac\u2019 Commands with Examples<\/a><\/p>\n<h3>Learn Linux \u2018more\u2019 Command<\/h3>\n<pre><strong># more \/var\/log\/auth.log<\/strong>\r\n<\/pre>\n<div class=\"code-label\" title=\"View Contents of auth.log File\">View Contents of auth.log File<\/div>\n<pre>Apr 12 11:50:01 tecmint CRON[6932]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 11:50:01 tecmint CRON[6932]: pam_unix(cron:session): session closed for user root\r\nApr 12 11:55:01 tecmint CRON[7159]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 11:55:01 tecmint CRON[7160]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 11:55:01 tecmint CRON[7160]: pam_unix(cron:session): session closed for user root\r\nApr 12 11:55:02 tecmint CRON[7159]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:00:01 tecmint CRON[7290]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 12:00:01 tecmint CRON[7290]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:05:01 tecmint CRON[7435]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 12:05:01 tecmint CRON[7436]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 12:05:01 tecmint CRON[7436]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:05:02 tecmint CRON[7435]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:09:01 tecmint CRON[7542]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 12:09:01 tecmint CRON[7542]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:10:01 tecmint CRON[7577]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 12:10:01 tecmint CRON[7577]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:15:01 tecmint CRON[7699]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 12:15:01 tecmint CRON[7700]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 12:15:01 tecmint CRON[7700]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:15:01 tecmint CRON[7699]: pam_unix(cron:session): session closed for user root\r\n....\r\n<\/pre>\n<p>Another way to use\u00a0<strong>more<\/strong>\u00a0command in conjunction (pipe) with other commands, such as\u00a0<a href=\"https:\/\/www.tecmint.com\/13-basic-cat-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">cat command<\/a>, as presented on below example:<\/p>\n<pre># cat \/var\/log\/auth.log | more\r\n<\/pre>\n<div id=\"attachment_20041\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-and-Navigate-Contents-of-File.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-20041\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-and-Navigate-Contents-of-File.gif\" sizes=\"auto, (max-width: 932px) 100vw, 932px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-and-Navigate-Contents-of-File.gif 932w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-and-Navigate-Contents-of-File-768x521.gif 768w\" alt=\"View and Navigate Contents of File\" width=\"932\" height=\"632\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">View and Navigate Contents of File<\/p>\n<\/div>\n<p>In order to navigate through the file line by line press\u00a0<code>Enter<\/code>\u00a0key or press\u00a0<code>Spacebar<\/code>\u00a0key to navigate one page at a time, the page being your current terminal screen size. To exit the command just press\u00a0<code>q<\/code>\u00a0key.<\/p>\n<p>A useful option of more command is the\u00a0<code>-number<\/code>\u00a0switch which allows you to set the number of line a page should contain. As an example display the\u00a0<code>auth.log<\/code>\u00a0file as a page of\u00a0<code>10<\/code>\u00a0lines:<\/p>\n<pre># more -10 \/var\/log\/auth.log\r\n<\/pre>\n<div id=\"attachment_20042\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-Top-10-Lines-of-File.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-20042\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-Top-10-Lines-of-File.gif\" sizes=\"auto, (max-width: 932px) 100vw, 932px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-Top-10-Lines-of-File.gif 932w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-Top-10-Lines-of-File-768x521.gif 768w\" alt=\"Show Only First 10 Lines of File\" width=\"932\" height=\"632\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Show Only First 10 Lines of File<\/p>\n<p>Also, you can display a page starting from a specific line number using the\u00a0<code>+number<\/code>\u00a0option as illustrated below:<\/p>\n<pre># more +14 \/var\/log\/auth.log\r\n<\/pre>\n<div class=\"code-label\" title=\"Show Only First 14 Lines of File\">Show Only First 14 Lines of auth.log File<\/div>\n<pre>Apr 12 12:09:01 tecmint CRON[7542]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:10:01 tecmint CRON[7577]: pam_unix(cron:session): session opened for user root by (\r\nuid=0)\r\nApr 12 12:10:01 tecmint CRON[7577]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:15:01 tecmint CRON[7699]: pam_unix(cron:session): session opened for user root by (\r\nuid=0)\r\nApr 12 12:15:01 tecmint CRON[7700]: pam_unix(cron:session): session opened for user root by (\r\nuid=0)\r\nApr 12 12:15:01 tecmint CRON[7700]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:15:01 tecmint CRON[7699]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:16:01 tecmint mate-screensaver-dialog: gkr-pam: unlocked login keyring\r\nApr 12 12:17:01 tecmint CRON[7793]: pam_unix(cron:session): session opened for user root by (\r\nuid=0)\r\nApr 12 12:17:01 tecmint CRON[7793]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:20:01 tecmint CRON[7905]: pam_unix(cron:session): session opened for user root by (\r\nuid=0)\r\nApr 12 12:20:01 tecmint CRON[7905]: pam_unix(cron:session): session closed for user root\r\nApr 12 12:25:01 tecmint CRON[8107]: pam_unix(cron:session): session opened for user root by (\r\nuid=0)\r\nApr 12 12:25:01 tecmint CRON[8108]: pam_unix(cron:session): session opened for user root by (\r\n<\/pre>\n<h3>Learn Linux \u2018less\u2019 Command<\/h3>\n<p>Similar to\u00a0<strong>more<\/strong>,\u00a0<strong>less<\/strong>\u00a0command allows you to view the contents of a file and navigate through file. The main difference between\u00a0<strong>more<\/strong>\u00a0and\u00a0<strong>less<\/strong>\u00a0is that\u00a0<strong>less<\/strong>\u00a0command is faster because it does not load the entire file at once and allows navigation though file using page\u00a0<strong>up<\/strong>\/<strong>down<\/strong>\u00a0keys.<\/p>\n<p>In can be used as a standalone command issued against a file or used with pipes with a multitude of Linux commands in order to narrow their screen output allowing you to scroll through results.<\/p>\n<pre># less \/var\/log\/auth.log\r\n# ls \/etc | less\r\n<\/pre>\n<p>You can navigate through the file line by line pressing\u00a0<code>Enter<\/code>\u00a0key. Page navigation can be handled with\u00a0<code>spaceba<\/code>r key. The page size is represented by your current terminal screen size. To exit command type\u00a0<code>q<\/code>\u00a0key, same way as for more command.<\/p>\n<p>A useful feature of\u00a0<strong>less<\/strong>\u00a0command is the use of\u00a0<strong>\/word-to-seach<\/strong>\u00a0option. For instance you can search and match all\u00a0<strong>sshd<\/strong>\u00a0messages from a log file by interactively specifying the\u00a0<code>\/sshd<\/code>\u00a0string.<\/p>\n<div id=\"attachment_20043\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-File-Content-Using-less-Command.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-20043\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-File-Content-Using-less-Command.gif\" sizes=\"auto, (max-width: 932px) 100vw, 932px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-File-Content-Using-less-Command.gif 932w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/04\/View-File-Content-Using-less-Command-768x521.gif 768w\" alt=\"View File Content Using less Command\" width=\"932\" height=\"632\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">View File Content Using less Command<\/p>\n<\/div>\n<p>In order to display a file staring at a specific line number use the following syntax:<\/p>\n<pre># less +5 \/var\/log\/auth.log\r\n<\/pre>\n<p>If you need to track down the number of every line with\u00a0<strong>less<\/strong>\u00a0command use the\u00a0<code>-N<\/code>\u00a0option.<\/p>\n<pre># less -N \/var\/log\/daemon.log\r\n<\/pre>\n<div class=\"code-label\" title=\"Show Number for Every Line in File\">Show Number for Every Line in File<\/div>\n<pre>      <strong>1<\/strong> Apr 12 11:50:01 tecmint CRON[6932]: pam_unix(cron:session): session opened for user root by (uid=0)\r\n      <strong>2<\/strong> Apr 12 11:50:01 tecmint CRON[6932]: pam_unix(cron:session): session closed for user root\r\n      <strong>3<\/strong> Apr 12 11:55:01 tecmint CRON[7159]: pam_unix(cron:session): session opened for user root by (uid=0)\r\n      <strong>4<\/strong> Apr 12 11:55:01 tecmint CRON[7160]: pam_unix(cron:session): session opened for user root by (uid=0)\r\n      <strong>5<\/strong> Apr 12 11:55:01 tecmint CRON[7160]: pam_unix(cron:session): session closed for user root\r\n      <strong>6<\/strong> Apr 12 11:55:02 tecmint CRON[7159]: pam_unix(cron:session): session closed for user root\r\n      <strong>7<\/strong> Apr 12 12:00:01 tecmint CRON[7290]: pam_unix(cron:session): session opened for user root by (uid=0)\r\n      <strong>8<\/strong> Apr 12 12:00:01 tecmint CRON[7290]: pam_unix(cron:session): session closed for user root\r\n      <strong>9<\/strong> Apr 12 12:05:01 tecmint CRON[7435]: pam_unix(cron:session): session opened for user root by (uid=0)\r\n     <strong>10<\/strong> Apr 12 12:05:01 tecmint CRON[7436]: pam_unix(cron:session): session opened for user root by (uid=0)\r\n     <strong>11<\/strong> Apr 12 12:05:01 tecmint CRON[7436]: pam_unix(cron:session): session closed for user root\r\n<\/pre>\n<p>By default the only way to exit\u00a0<strong>less<\/strong>\u00a0command is to hit\u00a0<code>q<\/code>\u00a0key. To change this behavior and automatically exit file when reaching the end of file use the\u00a0<code>-e<\/code>\u00a0or\u00a0<code>-E<\/code>\u00a0option:<\/p>\n<pre># less -e \/var\/log\/auth.log\r\n# less -E \/var\/log\/auth.log\r\n<\/pre>\n<p>To open a file at the first occurrence of a pattern use the following syntax:<\/p>\n<pre># less +\/sshd \/var\/log\/auth.log\r\n<\/pre>\n<div class=\"code-label\" title=\"Show Given Matching String in File\">Show Given Matching String in File<\/div>\n<pre>Apr 12 16:19:39 tecmint <strong>sshd<\/strong>[16666]: Accepted password for tecmint from 192.168.0.15 port 41634 ssh2\r\nApr 12 16:19:39 tecmint <strong>sshd<\/strong>[16666]: pam_unix(<strong>sshd<\/strong>:session): session opened for user tecmint by (uid=0)\r\nApr 12 16:19:39 tecmint systemd-logind[954]: New session 1 of user tecmint.\r\nApr 12 16:19:48 tecmint <strong>sshd<\/strong>[16728]: Received disconnect from 192.168.0.15: 11: disconnected by user\r\nApr 12 16:19:48 tecmint <strong>sshd<\/strong>[16666]: pam_unix(<strong>sshd<\/strong>:session): session closed for user tecmint\r\nApr 12 16:20:01 tecmint CRON[16799]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 16:20:02 tecmint CRON[16799]: pam_unix(cron:session): session closed for user root\r\nApr 12 16:25:01 tecmint CRON[17026]: pam_unix(cron:session): session opened for user root by (uid=0)\r\nApr 12 16:25:01 tecmint CRON[17025]: pam_unix(cron:session): session opened for user root by (uid=0)\r\n<\/pre>\n<p>The above command tells\u00a0<strong>less<\/strong>\u00a0to open\u00a0<strong>auth.log<\/strong>\u00a0file at the first match of\u00a0<code>sshd<\/code>\u00a0string.<\/p>\n<p>In order to automatically append the content of a file opened in\u00a0<strong>less<\/strong>\u00a0command use the\u00a0<code>Shift+f<\/code>\u00a0keys combination or run less with the following syntax.<\/p>\n<pre># less +F \/var\/log\/syslog\r\n<\/pre>\n<p>This makes less to run in interactive mode (live) and display new content on-fly while waiting for new data to be written to file. This behavior is similar to\u00a0<a href=\"https:\/\/www.tecmint.com\/view-contents-of-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">tail -f command<\/a>.<\/p>\n<p>In combination with a pattern you can watch the log file interactively with\u00a0<code>Shift+f<\/code>\u00a0key stroke while matching a keyword. To exit live mode just press\u00a0<code>Ctrl+c<\/code>\u00a0keys.<\/p>\n<pre># less +\/CRON \/var\/log\/syslog\r\n<\/pre>\n<p>Whether you decide to use\u00a0<strong>more<\/strong>\u00a0or\u00a0<strong>less<\/strong>, which is a personal choice, remember that\u00a0<strong>less<\/strong>\u00a0is more with\u00a0<strong>more<\/strong>features.<\/p>\n<p><b>Read Also:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/view-contents-of-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">Manage Files Effectively Using head, tail and cat Commands<\/a><\/p>\n<p><a style=\"font-size: 1rem;\" href=\"https:\/\/www.tecmint.com\/linux-more-command-and-less-command-examples\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>More\u00a0is a *nix command line used to display the contents of a file in a console. The basic usage of\u00a0morecommand is to run the command against a file as shown below: Read Also:\u00a0Learn Difference Between \u2018cat\u2019 and \u2018tac\u2019 Commands with Examples Learn Linux \u2018more\u2019 Command # more \/var\/log\/auth.log View Contents of auth.log File Apr 12 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/learn-why-less-is-faster-than-more-command-for-effective-file-navigation\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Learn Why \u2018less\u2019 is Faster Than \u2018more\u2019 Command for Effective File Navigation&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12131","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12131"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12131\/revisions"}],"predecessor-version":[{"id":12132,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12131\/revisions\/12132"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}