Is there a linux command or some way to look at logs from bottom up rather than from top towards bottom. I know about tail -n <number of lines>, but is there something that I can actually scroll and go from bottom up?


Some systems have tac, which is a whimsically-named backward cat. Without that, you can still do something like

awk '{print NR ":" $0}' $file | sort -t: -k 1nr,1 | sed 's/^[0-9][0-9]*://'
  • 8
    +1 for tac, did not know about that one :) – Johan Mar 7 '11 at 20:34
  • cat -n is like awk '{print NR,$0}', so slightly more lightweight. – glenn jackman Mar 16 '11 at 16:39
  • 1
    I was assuming that systems without tac might also lack the BSD-derived version of cat (USG-flavored cat didn't have -v, -n, etc. I think something triggered my "old ****".) – geekosaur Mar 16 '11 at 16:47

I think less +G is what you're looking for — it'll load up the file at the end, and you can use the up arrow (or k) to scroll back. Within the viewer, g will take you to the top of the file and G will take you back to the end. And F will scroll to the end and try to keep reading, like tail -f.

  • n1 +1 :) If you'll be so kind: Can you explain how to search the file from bottom up when using less with +G flag? – Oleg Belousov Jan 22 '14 at 17:20
  • 2
    @OlegTikhonov Sure. ? is used to search backwards in the file. – mattdm Jan 22 '14 at 17:36

The tac command is like a reverse "cat", if that's what you're after.

If you just want to view a file by starting at the bottom, why don't you use an editor or "less"?

  • 1
    Two problems I see with using editors are paginators: a) not all editors behave properly to network disconnects, meaning that the editor stays around even when the shell sends SIGHUP; b) many editors touch the directory (by creating a swap/temp file), which is disadvantageous if you want to keep the mtime of the directory stable. – Arcege Mar 7 '11 at 17:47

You can run less and then use M-> (that's the meta key, usually alt, and the '>' at the same time) to go to the bottom of the file. less supports scrolling.

  • 1
    The “go to last line” function is also usually bound to > (without Meta or ESC) and G. – Chris Johnsen Mar 8 '11 at 6:13
  • @Chris, I didn't realize Meta wasn't required in less. But that is was you would use in Emacs. – Carlos Rendon Mar 8 '11 at 17:37

If you are writing a nagios check the perl module File::ReadBackwards is useful


I use this script to read a file from bottom upward


echo -n elpmas.file # resulting file


while read line; do

   let ctr_line++

   tail -n $ctr_line | head -n 1 >> elpmas.file

done <sample.file

if sample.file contains


the result elpmas.file will be


Piping into tac also works, eg:

tail -n 3 /var/log/dmesg | tac

Soluction: Combine tac with less

tac $@ | less


sudo bash -c 'echo "tac \$@ | less" > /usr/local/bin/tacless'
sudo chmod +x /usr/local/bin/tacless


tacless /var/log/auth.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.