Chasing Your ‘Tail’ With Linux

‘GNU tail’ is a small utility which prints (by default) the last 10 lines of any file. This an amazing piece of software not only allows you to see the last part of a file but also enables you to monitor a file’s changes without opening the file.

‘tail’ can be used alone or can be combined with other commands like ‘grep’, ‘ls’ etc.

To use ‘tail’, let’s first create a text file. You can create the file by issuing following command in terminal;

touch my_file

Now open my_file with your favorite text editor (nano in my case) and write some lines. For this article, I have written the following 15 lines;

this is the 1st line
this is the 2nd line
this is the 3rd line
this is the 4th line
this is the 5th line
this is the 6th line
this is the 7th line
this is the 8th line
this is the 9th line
this is the 10th line
this is the 11th line
this is the 12th line
this is the 13th line
this is the 14th line
this is the 15th line

Now issue the following command in terminal;

tail my_file

It will print the last 10 lines which would be the “this is the 6th line” through “this is the 15th line”.

You can control the number of lines which ‘tail’ will print. You can either increase or decrease the number of lines. For example, if you want ‘tail’ to show only last 3 lines, you can do this by issuing the following command;

tail -n 3 my_file

Now it will print only last 3 lines. You can use any number of lines instead of 3. Or you can use a plus sign like;

tail -n+7 my_file

‘tail’ will start printing from 7th line to the end of the file.

You can view the desired file with respect to size. Issue the following command in terminal;

tail -c 14 my_file

And it will show the output of last 14 bytes. In my case, the output was;

the 15th line

‘tail’ not only displays the static output of a file but it can also monitor the file for changes. A ‘-f’ option is used with ‘tail’ and it starts acting like a monitoring tool which not only displays the last few lines but also constantly updates the output as the file changes. Here is a very popular example;

tail -f /var/log/message

‘tail’ will print the last 10 lines of ‘message’ file. If you now plug-in you USB stick, you will notice that the change in ‘message’ file will instantly be reported by ‘tail’. To release the cursor press Ctrl+c.

There are many other useful options which you can use with ‘tail’ like;

tail -q my_file        # never output headers
tail -v my_file        # always outputs headers

You can combine ‘tail’ with other utilities like ‘ls’, ‘grep’, ‘head’ etc.

You can combine ‘tail’ with ‘grep’ to get lines with some specific ‘word’.

tail -n 5 my_file | grep 14

It will print only those lines out of last 5 which contains the word ’14’. In my case the output was:

this is 14th line # ’14’ will be highlighted

‘tail’ can also be combined with ‘ls’ to get the list of last few files/folders. For example, if you issue the following command;

ls -l | tail -n 2

It will give a long listing of files/folders but will show the last 2 entries of the working directory.

These are just two examples of combining ‘tail’ with other utilities. There are countless examples of combination of ‘tail’ and other softwares.

‘GNU tail’ is a very handy tool. It can output any amount of data depending upon the options used. It makes the work of an ordinary user much easer and helps him/her find information in files more efficiently. To become an expert in Linux, this is a mandatory utility over which a user must have complete mastery. Hopefully, this tutorial gets you started chasing your tail!

Install the Latest Kernel in PCLinuxOS

Do you run PCLinuxOS 2007 or Minime 2008 and would you like to take advantage of the latest kernel for PCLinuxOS?  You can do this by enabling the ‘testing’ portion of the repository.

Read about Repository Control in PCLinuxOS

You’ll be looking for the ‘sections’ blank when viewing repository details and you’ll just need to add ‘testing’ to the end of the line (don’t replace the entires there already).  Once that is done, click the reload button in Synaptic and allow it to refresh your local rpm cache.

Click the ‘search’ button and search for the keyword ‘kernel’.  Look for the highest number of kernel that is returned.  At the time of this writing, the kernel was the newest kernel for PCLinuxOS (it has .27 patches all over in it…so it’s quite a nice kernel).  Click and install that kernel and allow it to select any packages it needs to install.  Once installed, you can remove the word testing from the repository (this is recommended to prevent your system from downloading ALL testing packages/updates) and click the reload button for Synaptic.

Reboot and choose the new kernel on your grub menu.  Test things to see how they work.  If everything is good to go, congratulations!  You’ve just installed the latest kernel in PCLinuxOS.

To make this kernel the default one, you can use the PCLinuxOS Control Center and Change the Way the System Boots.  I’ll cover this in a later post.  Hope this helps a few of you out there.  I know it is often asked on IRC.

Customizing PCLinuxOS 2008 Minime

Putting it Together

Build Your Own PCLOS

So, HowtoForge has a perfect desktop for PCLinuxOS 2007…how about something similar for 2008 MiniMe? I won’t go into near as much detail as they do there but I’ll go over how I get my desktop up and rolling after a fresh install of PCLinuxOS Minime 2008.

MiniMe is the lesser known offspring of PCLinuxOS 2007 that ships with a kernel and is a minimalistic installation of the KDE desktop 3.5.9. Texstar provides this distribution for those wanting to remaster their installations…it’s a base for other remastered projects like PCLinuxOS Gnome. Remastering and the Make LiveCD wizard enable users to customize their distribution and make a bootable backup CD with all their customizations OR release their own customized distribution. You can also use the Make LiveUSB wizard to create your very own thumbdrive PCLinuxOS.

I found it strange that no one had written anything about MimiMe-to on getting PCLinuxOS 2008 MiniMe up and running as a desktop replacement so I decided to give it a go. The aim of this article isn’t to copy Howtoforge’s great series on perfect installations…but to show how I get PCLinuxOS 2008 Minime up to a perfect installation for me. This means all web video, audio, fonts, and tools I need are installed. So let’s get at it.

What Do We Need?

First and foremost, do a complete upgrade of your fresh installed system. Open Synaptic >> Reload >> Mark all Upgrades >> Apply. It’s going to take a while to get all the updates you’ll need. Do NOT enable the testing repository until after you install your graphics driver at the end of this article…just perform a straight update from main.

Now let’s start installing stuff that is needed on a daily basis. I’m more of a lightweight type of guy so I don’t need robust office applications so my tastes may not line up with yours. Please substitute applications where you see fit…the repositories most likely have them.

To give a brief, high level overview of my daily use applications:

  • firefox3
  • Opera
  • K3B
  • konversation
  • pidgin
  • skype_static
  • koffice
  • gimp
  • Amarok
  • claws-mail
  • kdeaddons-kate
  • kdeaddons-ark
  • kdegraphics-ksnapshot (for taking screenshots)

Those are the high level applications I use on a daily basis to get things done. Whenever you are prompted to mark other packages for install, go ahead and and choose “mark”. Click apply and let the your daily use applications install.

Read more

Firewalls and Routers Help

Do you cringe when a new vulnerability is announced in Windows? Do you sit idlely behind a standard all-in-one firewall/router that you picked up from a computer store? Did you know that you could be vulnerable to hacking?

I wrote a how-to for a Linux firewall utilizing an old computer and posted it to my favorite ‘for free’ tech support site,  Hopefully, this will help some of you that need it.

LinuxBlog Forum Tip:

Daniweb Tutorial Direct: