Efficiently Navigating Large Files in Linux: Mastering Backward Reading in `less` and `more`


4 views

When working with large log files or data dumps in Linux, developers often need to quickly jump to the end of a file and read backward. While less +G filename provides a basic solution, it lacks efficient navigation features like page scrolling or backward search.

Here's how to supercharge your file navigation:


# Jump to end and enable full navigation
less +G -N filename

# Alternative: start at end with immediate backward search
less +?pattern filename

Once in less, use these key combinations:

  • Shift+G - Jump to end of file
  • Ctrl+B - Page up (backward)
  • ? - Backward search (type pattern after)
  • N - Repeat search in backward direction

Add these aliases to your .bashrc:


alias tailess='less +G -N'
alias revsearch='less +?'

While less powerful, more can be used:


# View from end (limited functionality)
tac filename | more

For examining Apache logs:


less +G -N /var/log/apache2/access.log
?500

This jumps to the end and searches backward for HTTP 500 errors.


When working with large log files or text documents in Linux, it's often useful to start reading from the end. The most basic way to do this in less is:

less +G filename

This command opens the file with the cursor positioned at the end. However, navigation is limited - you can only scroll up line by line using the up arrow key.

For more efficient backward reading, try these less commands:

less +GG filename  # Starts at end and shows status
less +G -N filename  # Shows line numbers while navigating

Once the file is open, use these key combinations:

  • Ctrl+b or Page Up: Scroll backward one page
  • Shift+G: Jump to end of file (useful if you've moved up)
  • ?: Start backward search (type pattern, press Enter)
  • N: Repeat previous search backward

tac with less /h2>

For true reverse-order viewing, combine tac with less:

tac filename | less

This displays the file in reverse order, allowing you to navigate normally from what was originally the end of the file.

Add this alias to your .bashrc for quick access:

alias lessend='less +G'

Or for the tac approach:

alias reverseless='tac | less'

For gzipped files, use:

zcat filename.gz | tac | less

Or with less's built-in compression support:

less +G filename.gz