Saturday, March 24, 2012

Pimp your Tail command


The default settings of the TAIL command is to output the last 10 lines of a file

eg 
tail /var/log messages

will output the last 10 lines of your /var/log/messages file

Mar 24 11:25:20 mirage dbus-daemon[1094]: dbus[1094]
Mar 24 11:25:20 mirage dbus[1094]: [system] Successfully activated service 'org.freedesktop
Mar 24 11:27:44 mirage dbus-daemon[1094]: dbus[1094]: [system] Activating service name
Mar 24 11:27:44 mirage dbus[1094]: [system] Activating service name='net.reactivated
Mar 24 11:27:44 mirage dbus-daemon[1094]: Launching FprintObject
Mar 24 11:27:44 mirage dbus[1094]: [system] Successfully activated service 'net.reactivated.Fprint'
Mar 24 11:27:44 mirage dbus-daemon[1094]: dbus[1094]: [system] 
Mar 24 11:27:44 mirage dbus-daemon[1094]:
Mar 24 11:27:44 mirage dbus-daemon[1094]: ** Message: entering main loop


This alias changes the default setting of tail so that it outputs all the lines that can fit on your screen.

just add the following to your .bashrc if you use bash or your .zshrc if you use zsh as your terminal editor.


alias tail='tail -n $((${LINES:-`tput lines 2>/dev/null||echo -n 80`} - 7))'

then source youre .bashrc or .zshrc by typing
source .bashrc or
source .zshrc

or just restart your terminal

next time you run  tail on a file you will get as many lines as will fill up your screen.



No comments: