A Lightweight Low-Battery Warning Monitor for GTK+ 3.x desktops

A laptop’s battery gives us the comfort of storing power which we can use later. However, sometimes this comfort turns into pain.  For example, if we take our laptop with us, thinking that it’s charged (but it actually isn’t), or if we leave our laptop powered on and it silently turns off resulting in the loss of valuable work.

It is with this in mind that a programmer developed a simple battery monitor in Python with the following capabilities:

  1. The program should be customizable and lightweight.
  2. It should work in the background without any disturbance.
  3. It can allow the user to set a minimum charge threshold.
  4. Upon reaching that threshold, the program should not only display a desktop notification but also play a sound to force the user to plug in the charger.
  5. When the charger is connected, it should stop the notifications immediately but remain running to watch for future problems.

The program has been tested on Arch, Ubuntu and Mint, so, if this sounds like something you’d be interested in, why not give it a try!

Radio Tray – A Radio Player That Fits In System Tray


Radio Tray is a very simple application that plays your favourite radio stations and it does so from the system tray, meaning any station you want to listen to is only two clicks away. Naturally you’ll need to add your favorite streams to this program before it will actually be useful. Most websites offering streaming will give you access to a “.pls” file. Copy the link to this file and you can add it to Radio Tray. It supports most media formats as well as PLS, M3U, ASX, WAX and WVX playlist format. You can even bookmark the stations you really like for easy access, which is pretty nice too. To install Radio Tray in Ubuntu Linux, launch Ubuntu Software Center from Applications menu (at the top) and search for “Radio Tray”. From the results, select “Install” and you are all set to use this amazing piece of software.

ubuntu-software-center

Radio Tray can be launched from “Sound & Video” menu under “Applications”. It will appear in the system tray area. This is the beauty of this software that as it runs in system tray so it does not consumes much system resources as it does not require any browser window or any other heavy application to function. Radio Tray will launch in system tray and will not automatically play any station. To play the radio station, click on the Radio Tray (tray) icon and select the station from drop down list (you may require extra plugins for proper functioning of the application e.g gstream libraries).

radio-tray-unconfigured

Perhaps the pre-configured radio stations may not interest you. You can not only add your favourite channels but even Remove or Edit any existing channel. To Add/Remove channel(s) in Radio Tray, Right Click on the tray icon and Select “Configure radios…”. A dialogue box will appear. Here you can Add new channels, Remove or Edit existing channels and Move the Channels UP or Down in the list. Lets, now add a radio station to Radio Tray. Go to: http://www.shoutcast.com/ and search for some radio station (say, rock). From the results, just copy the link of any radio station. Now come back to “Configure Radios” and Click on “Add” Button. In the “Radio name” box enter any friendly name (say Soft Rock) of the radio station while in the “URL” paste the link of the radio station.

radio-tray-add-station

Your new radio station is now added into the channel lists of Radio Tray and you can listen to it just by selecting it from the drop down list of Radio Tray.


radio-tray-configured

If your favorite station doesn’t have a standard M3U or PLS playlist posted on their web site, you can always find the stream’s URL by other means. Radio Tray isn’t incredibly feature-filled, but on those occasions you just need a simple unitasker, it’s perfect for getting the job done and staying out of your way. Its a perfect substitute for proprietary radio softwares and not only available in .deb format but also in source format.

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!

Using ‘Alias’ in Linux

There comes a time in every Linux users’ life when you will open the Terminal more often than not because you have realized that it is faster, more efficient and more powerful than GUI (Graphical User Interface).  You’ll have started to learn more and more commands and now feel more comfortable with command prompt.  The command prompt is all about commands – short commands as well as long commands.  If you are like me then you may not like to type the long commands (or even small commands) 🙂

You may be thinking about some way to avoid typing commands over and over. Enter the ‘alias’.

The ‘alias’ tool is a way to make the complicated things simple (and simple things simpler). You can use ‘alias’ instead of long (or even short) commands.  Now let’s see how the ‘alias’ works.

‘alias’ can make difficult and lengthy commands easy. The general format of ‘alias’ is:

alias Any_Word=”Command”

It means you linked an existing command to a (New) Word. This ‘Any_Word’ may contain anything – any alpha-numeric symbol, ‘Any_Word’ as well as ‘Command’ are interchangeable and can be used for the same purpose.

Simple Commands Made Simpler

As an example, ‘ls -l’  is used for listing directory contents in ‘long listing format’. This ‘ls -l’ can be replaced with a simpler alias. You can set the ‘alias’ for ‘ls –l’ as follows:

alias ll=”ls –l”

Now you just have to type ‘ll’ (without quotes) to get ‘long listing format’.

Or if you frequently misspell ‘ls’ as ‘sl’ and don’t want to install ‘sl’ package, then, you can use the following alias:

alias sl=”ls”

Now, whenever you type ‘sl’ in terminal, it will give you same results as ‘ls’.

Now consider even simpler example. To close a Terminal (or logout), you have to type ‘exit’ in Terminal. This ‘exit’ command can be made even simpler by using the following ‘alias’:

alias x="exit"

Now, you only have to type ‘x’ in Terminal to ‘exit’

Other examples of ‘alias’ are:

alias cp="cp -iv"
#make copy operation interactive and verbose
alias rm="rm -iv"
#make remove operation interactive and verbose
alias mv="mv -iv"
#make move operation interactive and verbose

Make Package Management A Bit Simpler

If you use Debian (or its derivatives) then you will be familiar with APT.  It is an excellent package manager.

In Ubuntu, to install software using APT, you have to use the following command:

sudo apt-get install <sofware_name>

It is a long command and consumes a lot of your time and energy 🙂

You can shorten this command by using ‘alias’.  Issue the following command in Terminal:

alias Install=”sudo apt-get install”

You can obviously use your own word instead of ‘Install’.

Now, you just have to type:

Install <software_name>

to install the (same) software. Simple, isn’t it?

You can simplify other aspects of APT. For example, you can use the following ‘alias’:

alias Remove=”sudo apt-get remove”

to uninstall a software.

Some other examples of attaching APT with ‘alias’ are:

alias Update=”sudo apt-get update”
alias Upgrade=”sudo apt-get upgrade”
alias Search=”apt-cache search”
alias Autoremove=”sudo apt-get autoremove”
alias Autoclean=”sudo apt-get autoclean”
alias Purge=”sudo apt-get remove –purge”

and so on…

A Very Interesting ‘alias’ For A Difficult Keyboard Button

On some keyboards, the dot (.) button is at very difficult position and if you have to use it more than once, it becomes even more difficult.  That’s why ‘cd ..’ is the command which I mistype the most.  This complication can be easily removed by using following ‘alias’ (you can use any other word instead of a dot):

alias .=”cd ..”
alias ..=”cd ../..”
alias ...=”cd ../../..”
alias ....=”cd ../../../..”

Using Internet From Terminal

If you regularly use lynx to browse the internet in terminal then you have to type long urls with lynx to visit the web pages.  You can simplify these long urls by using ‘alias’:

alias Google=”lynx http://www.google.com/”
alias Yahoo=”lynx http://www.yahoo.com/”
alias yalb =”lynx http://linux-blog.org/”

and so on…

Now just type Google, Yahoo or yalb to visit the respective web sites.

Simple ‘alias’ For More Complicated Commands

Long commands are not only difficult to remember but also take more time to type; when you have to use them on daily basis, you become frustrated when typing them again and again and again… So, ‘alias’ are more suitable for long and complicated commands.

Let’s consider an example.

To find the top 10 largest files in your system, you can set the following ‘alias’:

alias top10files=”find . -type f -exec ls -sh {} \; | sort -n -r | head -10”

You can even mix different commands with ‘alias’.  For instance, if you regularly use ‘tail’ and direct its output to file to later view that file, you can set a very simple ‘alias’ to do this cumbersome operation in 1 word:

alias Tail=”tail /var/log/messages > hello.txt;cat hello.txt”

Now just enter ‘Tail’ and viola! All is done at once.

You can use any file with tail and direct its output and you can even use ‘nano’ or ‘vi’ to view/edit its output.

Here’s another example… ‘alias’ to connect to a remote server:

alias any_name=”ssh <remote_server_address> -l <username> -p <port>”

You can even create ‘alias’ for your bash scripts, like:

alias clc=”sh /home/user/myscripts/calc.sh”

Now that you have set a few different ‘alias’  you might want to check that which ‘alias’ are set on your system.  To do that, just issue the following command:

alias

and it will list all the set ‘alias’ you have.

To remove an ‘alias’, just issue the ‘unalias’ command, like:

unalias Google

and now typing Google in terminal will do nothing (as it was set with lynx).

To remove all the ‘alias’, issue the following command and all the ‘alias’ are gone:

unalias –a

We have discussed the way of setting the ‘alias’ for different kinds of commands.  But setting ‘alias’ in this way be temporary.  When you reboot you PC, all the ‘alias’ which you have set will be gone.  This does not mean that you have to set all the ‘alias’ every time you boot your PC.  If you have set an ‘alias’ and you liked it so much that you want it to permanently reside in you PC, just add this alias in ‘.bashrc’ file in you home directory. For example, if you want ‘alias’:

Install <software_name>

to permanently reside in your PC then user your favorite text editor and add the following line in your ‘~/.bashrc’ file:

alias Install=”sudo apt-get install”

Now this ‘alias’ will not vanish into thin air when you reboot your PC. Only those ‘alias’  which are listed in ‘~/.bashrc’ file will be permanent.

This guide is just a preview about ‘alias’.  It is just about basic ways of using ‘alias’ to make your life simpler.  ‘GNU alias’ is a tool which can simplify your life immensely.  But unfortunately this tool is not given the attention it deserves.  In short, it is such a powerful tool that if you give it proper time, it can make you forget typing 🙂

GNU find – A Multidimensional Tool

Beginners are mostly afraid of command prompt.  Whenever they see a command prompt, they immediately say “its very difficult”.  But it’s not true.  The Command prompt is as friendly as GUI (Graphical User Interface), provided if you use it with proper procedure.

Most people use GUI tools to search for files.  They don’t realize that they can use command line tools to search for them as well! GNU ‘find’ is such like a tool which can not only search files but can even copy, move or delete these files on the fly.

So let’s see that how ‘find’ works.

Find Your Lost Files!

Let’s start from a simple example:

Suppose you want to search for a file named ‘master.txt’ in your home directory.

Open the Terminal and issue the following command:

find . -name “master.txt”

‘find’ will immediately show the results.  If ‘find’ does not show any result, this means that the file, in our case, ‘master.txt’, does not exist.  It is not always the case that you want to find something in you home directory.  The lost/desired file may be anywhere in your computer.  Suppose you want to find a file named ‘space-01.jpg’ and you only know that its located somewhere in /usr directory. You can find it by issuing following command in Terminal:

find /usr -name “space-01.jpg”

and ‘find’ will tell you that this is located under /usr/share/backgrounds.

Using Wildcards

Maybe you want to search for a file but you don’t know its exact name?  Don’t worry!  You can still locate the file using ‘GNU find’ and wildcard will help you in this regard. Wildcards are a way of searching files when you don’t know much about your desired file.

One of the commonly used wildcard is asterisk (*).  Lets consider an example to better understand the things.

Suppose you want to search a file named ‘Jumping_Flowers’ but you only remember the ‘Jumping‘ part of the file name.  So issue the following command in Terminal:

find . -name “Jumping*”

And it will display all the files starting with the word ‘Jumping’.  You can use asterisk (*) anywhere with a file name.  For example:

find . -name “*Jumping*”

And it will display all the files which contains the word ‘Jumping’.

Here are some more examples of use of a wildcard:

find . -name “Jumping*Flowers*”
find . -name “*Jumping*Flowres.mp3”

Searching For Different File Types

Sometimes you are not looking for some specific file but you are looking for a group of files.  For example, you may be looking for all the .txt files in your home directory.  To find all the .txt files, you will give the following command in Terminal:

find . -name *.txt

In case of mp3 files, the above command will be:

find . -name *.mp3

When You Want to Search with Respect to Time

If you want to search for files by the last time they were accessed, you can use -amin flag with ‘find’.  In this case you have to put a minus (-) sign before the time.  The time here is in minutes.  In order to search for .doc files which were accessed in last 10 minutes, you will give the following command:

find . -amin -10 -name "*.doc"

Similarly, to search for .doc files which were modified in last 20 minutes, you will use -mmin option as follows:

find . -mmin -20 -name “*.doc”

Search For Files which are Eating Your Hard Disk

There may be files on your system which are not only huge in size but also located obscure places.  You may also may not know when they were last accessed.  You have to use -size option with ‘find’ to locate them.

Let’s see how we can do this:

find . -size +100M

It will list all those files which are greater than 100 Megabytes.  You can replace ‘M’ with ‘G’ (for Gigabyte) or with ‘k’ (for Kilobyte)

Copy, Move, or Delete Unwanted Files on the Fly

Copy – ‘find’ can also be used to copy or backup your files.  You can use ‘find’ to copy certain files from one location to other with one simple command.

Suppose you want copy all of your mp3 songs from your home directory to your Windows Partition.  Enter the following command in Terminal:

find . -name "*.mp3" -exec cp {} /path/to/Windows_Drive \;

And all of your mp3 files will be copied to the desired Drive/Folder.

Move – There may be situations that you quickly want to move all of your document files from your Hard Disk to your USB to keep them safe.  To move all of your documents from your home directory to your USB, you will issue the following command:

find . -name "*.doc" -exec cp {} /path/to/USB \;

Delete – Suppose there are a lot of .tmp files and you want to get rid of them at once.  Again ‘GNU find’ is at your service and does the work for you.  Issue the following in Terminal and all of the .tmp files are gone…

find . -name '*.tmp' -exec rm {} \;

Which Files are Owned by You and Which Are Not?

There may be a situation when you want to know that which files in some other directories (or even in your home directory) are owned by some other user of your computer.

Suppose there is another user named ‘blackstar’ with whom you are sharing your PC.  Now you want to know that which .doc files in Windows Directory is owned by this user ‘blackstar’.  You can do this by issuing the following command:

find /path/to/Windows_Drive -user blackstar -name “*.doc”

Just replace ‘blackstar’ with your username to search on your system.

Direct the Output of ‘find’ to a File

You can save the results of your ‘find’ command to a text file which will allow you to examine the results in detail at some later time (or to create playlist of your songs).  For this purpose a greater than (>) sign is used (referred to as “piping the command”).

Suppose you want to save the list of all the mp3 songs in your home directory to a text file (which you can later share with your friend), you can do this by:

find . -name "*.mp3" > mp3.txt

It will save the complete path to all of your mp3 songs in the file named mp3.txt.

Find, a Handy Command Line Tool

This article is basically directed towards new users of Linux which are not much familiar with command prompt. This is a small but comprehensive article about ‘GNU find’ . The man pages of ‘find’ list a huge number of options which are difficult to explain in detail in one small article. I tried to cover those option which are commonly used. Obviously, to know more about such a powerful tool , one has to visit its man pages again and again and spend a lot time with ‘find’ 🙂

Creative Commons License
Except where otherwise noted, the content on this site is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.