• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

Learn Why ‘less’ is Faster Than ‘more’ Command for Effective File Navigation

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
5
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Learn Linux ‘more’ Command
  2. Learn Linux ‘less’ Command

More is a *nix command line used to display the contents of a file in a console. The basic usage of more command is to run the command against a file as shown below:

Read Also: Learn Difference Between ‘cat’ and ‘tac’ Commands with Examples

Learn Linux ‘more’ Command

# more /var/log/auth.log
View Contents of auth.log File
Apr 12 11:50:01 tecmint CRON[6932]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 11:50:01 tecmint CRON[6932]: pam_unix(cron:session): session closed for user root
Apr 12 11:55:01 tecmint CRON[7159]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 11:55:01 tecmint CRON[7160]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 11:55:01 tecmint CRON[7160]: pam_unix(cron:session): session closed for user root
Apr 12 11:55:02 tecmint CRON[7159]: pam_unix(cron:session): session closed for user root
Apr 12 12:00:01 tecmint CRON[7290]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 12:00:01 tecmint CRON[7290]: pam_unix(cron:session): session closed for user root
Apr 12 12:05:01 tecmint CRON[7435]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 12:05:01 tecmint CRON[7436]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 12:05:01 tecmint CRON[7436]: pam_unix(cron:session): session closed for user root
Apr 12 12:05:02 tecmint CRON[7435]: pam_unix(cron:session): session closed for user root
Apr 12 12:09:01 tecmint CRON[7542]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 12:09:01 tecmint CRON[7542]: pam_unix(cron:session): session closed for user root
Apr 12 12:10:01 tecmint CRON[7577]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 12:10:01 tecmint CRON[7577]: pam_unix(cron:session): session closed for user root
Apr 12 12:15:01 tecmint CRON[7699]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 12:15:01 tecmint CRON[7700]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 12:15:01 tecmint CRON[7700]: pam_unix(cron:session): session closed for user root
Apr 12 12:15:01 tecmint CRON[7699]: pam_unix(cron:session): session closed for user root
....

Another way to use more command in conjunction (pipe) with other commands, such as cat command, as presented on below example:

# cat /var/log/auth.log | more
Learn Why ‘less’ is Faster Than ‘more’ Command for Effective File Navigation

View and Navigate Contents of File

In order to navigate through the file line by line press Enter key or press Spacebar key to navigate one page at a time, the page being your current terminal screen size. To exit the command just press q key.

A useful option of more command is the -number switch which allows you to set the number of line a page should contain. As an example display the auth.log file as a page of 10 lines:

# more -10 /var/log/auth.log
Learn Why ‘less’ is Faster Than ‘more’ Command for Effective File Navigation

Show Only First 10 Lines of File

Also, you can display a page starting from a specific line number using the +number option as illustrated below:

# more +14 /var/log/auth.log
Show Only First 14 Lines of auth.log File
Apr 12 12:09:01 tecmint CRON[7542]: pam_unix(cron:session): session closed for user root
Apr 12 12:10:01 tecmint CRON[7577]: pam_unix(cron:session): session opened for user root by (
uid=0)
Apr 12 12:10:01 tecmint CRON[7577]: pam_unix(cron:session): session closed for user root
Apr 12 12:15:01 tecmint CRON[7699]: pam_unix(cron:session): session opened for user root by (
uid=0)
Apr 12 12:15:01 tecmint CRON[7700]: pam_unix(cron:session): session opened for user root by (
uid=0)
Apr 12 12:15:01 tecmint CRON[7700]: pam_unix(cron:session): session closed for user root
Apr 12 12:15:01 tecmint CRON[7699]: pam_unix(cron:session): session closed for user root
Apr 12 12:16:01 tecmint mate-screensaver-dialog: gkr-pam: unlocked login keyring
Apr 12 12:17:01 tecmint CRON[7793]: pam_unix(cron:session): session opened for user root by (
uid=0)
Apr 12 12:17:01 tecmint CRON[7793]: pam_unix(cron:session): session closed for user root
Apr 12 12:20:01 tecmint CRON[7905]: pam_unix(cron:session): session opened for user root by (
uid=0)
Apr 12 12:20:01 tecmint CRON[7905]: pam_unix(cron:session): session closed for user root
Apr 12 12:25:01 tecmint CRON[8107]: pam_unix(cron:session): session opened for user root by (
uid=0)
Apr 12 12:25:01 tecmint CRON[8108]: pam_unix(cron:session): session opened for user root by (

Learn Linux ‘less’ Command

Similar to more, less command allows you to view the contents of a file and navigate through file. The main difference between more and less is that less command is faster because it does not load the entire file at once and allows navigation though file using page up/down keys.

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.

# less /var/log/auth.log
# ls /etc | less

You can navigate through the file line by line pressing Enter key. Page navigation can be handled with spacebar key. The page size is represented by your current terminal screen size. To exit command type q key, same way as for more command.

A useful feature of less command is the use of /word-to-seach option. For instance you can search and match all sshd messages from a log file by interactively specifying the /sshd string.

Learn Why ‘less’ is Faster Than ‘more’ Command for Effective File Navigation

View File Content Using less Command

In order to display a file staring at a specific line number use the following syntax:

# less +5 /var/log/auth.log

If you need to track down the number of every line with less command use the -N option.

# less -N /var/log/daemon.log
Show Number for Every Line in File
      1 Apr 12 11:50:01 tecmint CRON[6932]: pam_unix(cron:session): session opened for user root by (uid=0)
      2 Apr 12 11:50:01 tecmint CRON[6932]: pam_unix(cron:session): session closed for user root
      3 Apr 12 11:55:01 tecmint CRON[7159]: pam_unix(cron:session): session opened for user root by (uid=0)
      4 Apr 12 11:55:01 tecmint CRON[7160]: pam_unix(cron:session): session opened for user root by (uid=0)
      5 Apr 12 11:55:01 tecmint CRON[7160]: pam_unix(cron:session): session closed for user root
      6 Apr 12 11:55:02 tecmint CRON[7159]: pam_unix(cron:session): session closed for user root
      7 Apr 12 12:00:01 tecmint CRON[7290]: pam_unix(cron:session): session opened for user root by (uid=0)
      8 Apr 12 12:00:01 tecmint CRON[7290]: pam_unix(cron:session): session closed for user root
      9 Apr 12 12:05:01 tecmint CRON[7435]: pam_unix(cron:session): session opened for user root by (uid=0)
     10 Apr 12 12:05:01 tecmint CRON[7436]: pam_unix(cron:session): session opened for user root by (uid=0)
     11 Apr 12 12:05:01 tecmint CRON[7436]: pam_unix(cron:session): session closed for user root

By default the only way to exit less command is to hit q key. To change this behavior and automatically exit file when reaching the end of file use the -e or -E option:

# less -e /var/log/auth.log
# less -E /var/log/auth.log

To open a file at the first occurrence of a pattern use the following syntax:

# less +/sshd /var/log/auth.log
Show Given Matching String in File
Apr 12 16:19:39 tecmint sshd[16666]: Accepted password for tecmint from 192.168.0.15 port 41634 ssh2
Apr 12 16:19:39 tecmint sshd[16666]: pam_unix(sshd:session): session opened for user tecmint by (uid=0)
Apr 12 16:19:39 tecmint systemd-logind[954]: New session 1 of user tecmint.
Apr 12 16:19:48 tecmint sshd[16728]: Received disconnect from 192.168.0.15: 11: disconnected by user
Apr 12 16:19:48 tecmint sshd[16666]: pam_unix(sshd:session): session closed for user tecmint
Apr 12 16:20:01 tecmint CRON[16799]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 16:20:02 tecmint CRON[16799]: pam_unix(cron:session): session closed for user root
Apr 12 16:25:01 tecmint CRON[17026]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 12 16:25:01 tecmint CRON[17025]: pam_unix(cron:session): session opened for user root by (uid=0)

The above command tells less to open auth.log file at the first match of sshd string.

In order to automatically append the content of a file opened in less command use the Shift+f keys combination or run less with the following syntax.

# less +F /var/log/syslog

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 tail -f command.

In combination with a pattern you can watch the log file interactively with Shift+f key stroke while matching a keyword. To exit live mode just press Ctrl+c keys.

# less +/CRON /var/log/syslog

Whether you decide to use more or less, which is a personal choice, remember that less is more with more features.

Read Also: Manage Files Effectively Using head, tail and cat Commands

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

Upgrading Bash for the Shellshock Vulnerability

Next Post

How to Rename File While Downloading with Wget in Linux

Next Post

How to Rename File While Downloading with Wget in Linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet