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.
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.
Yeah, 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.
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…
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
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
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)
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.
Yay For Powershell.
Hope you learned something new today! Let me know what you think.
5 Comments
Francois-Xavier Cat · January 31, 2014 at 10:04 pm
Cool! I did not know about the -tail and -last parameters 🙂
Thanks!
Kevin · February 5, 2014 at 2:55 pm
Love the hint on powershell. I have used tail on *unix for a while.
Thanks,
Kevin
Rob Nelson · March 7, 2014 at 4:04 pm
In *nix, you can leave out the ‘n’ and just use -, like “tail -5 *log” to get the last 5 lines.
C-Rad · March 7, 2014 at 4:05 pm
Cool! Thanks for the tip!
Friday Shorts - Log Insight, @vNoob's tail, ViPR, Best Practices | mwpreston.net · February 7, 2014 at 10:17 am
[…] title here but I couldn't think of anything Conrad hasn't already said in his latest post vNoob Guide to Getting Tail. Now I have no idea how well Conrad does with the ladies, but he certainly gives a great […]