vNoob Guide to Getting Tail

Being in the Tech Industry it can something some of us think about quite often. We think about it at work, when we go home, when we are out with friends, in the shower, and everywhere. For those who don’t have much experience with it, it can be awkward. For those who have the courage to try, it can difficult knowing how everything works and where everything goes.

Don’t worry my friends. I am here to help.

By the end of this article hopefully everyone will be off to a great start to getting and understanding the CLI Tail command. 😉  (And stick around for using tail in Powershell)

So Let’s Get Started

The first thing to know about the tail command is that you need something to tail. This will generally be a text file of some kind, and is almost always a log file.

logfiles

Log files on ESXi hosts are in the /var/log directory. For a full list of where all log files can be found, and what each log file is for, check this link.

Let’s pick log file and run a tail, by default tail will show the last 10 lines.

DefaultTailYeah, my screenshot cut off some on the right, but you get the idea.

If you want to see more or less than 10 lines you can run the -n parameter. -n being the number of lines you want to see.

TailNumLines

Instead of -n you can use -c, however -c will show that many bytes of the log file. Although I am sure there is a use case for the -c parameter, I am not sure what it would be.

Tail will even do multiple log files at the same time…

MultiLogDefault

Just providing two log files will give you an output for each, with a header letting you know which log file you are viewing.

If you really don’t like the headers, or like not knowing which messages are from which log file use -q

MultiLogNoHead

And if you use -v it will always show you the header, even if you are only looking at one log file.

A lot of people use tail with the -f parameter. This parameter not only pulls info from the log file, but will update your screen/prompt with new lines as the log file grows, which is neat! Using the -s parameter you can even define how often(in seconds) you want the screen updated, but -s isn’t necessary.

Now I can’t show the screen updating with  a screenshot, but I will show you how the command looks with those parameters

LogUpdate

Awesome! That pretty much sums up Tail.

But WAIT! There’s More!

I would be remiss if I didn’t also talk about how to tail in Powershell!!

Using tail in Powershell involves using the Get-Content cmdlet along with the -Tail or -Last parameter(they are the same thing)

PowershellTail

With this I was able to tail the last to line of a vCenter log. Even cooler is that I did this over the network!

You can also use the -Wait parameter to give update your powershell window when the log is updated, just like the tail -f command.

PowershellcurrentTail

Yay For Powershell.

Hope you learned something new today! Let me know what you think.

5 Responses to vNoob Guide to Getting Tail

Leave a Reply