Reverse cat (concatenate) a Text File

There’s a command for that!

So everyone in the Linux/BSD world has used the command “cat” to print out the contents of a file to screen. Infact, I find it hard to believe you can use Linux or BSD properly without using that command on log files and any other text-based file.

But say you have a 1MB text file – an apache logfile for example – that you want to print the contents of to the screen, but you’d rather see the newest contents first – how do you do that?  You certainly don’t want to cat the file and wait until the end…

Well, it’s simple.. what’s the opposite of cat?  tac of course!

From the tac manpage:  tac – concatenate and print files in reverse

So, the next time you want to see the contents of a text file, but want to see the newest content first, tac is the command you need:

tac filename.log

Or, as you’ll probably need (to stop the output just flooding to the screen), you can pipe it to more, just as you can a normal cat.

tac filename.log | more