Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 20 down vote accepted

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]*://'
share|improve this answer
+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
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.

share|improve this answer
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 Tikhonov Jan 22 '14 at 17:20
@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"?

share|improve this answer
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.

share|improve this answer
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

share|improve this answer

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

share|improve this answer

Piping into tac also works, eg:

tail -n 3 /var/log/dmesg | tac
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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