Skip to content

Recent Articles

12
Jul

Triggering Commands on File/Directory Changes in Ubuntu

He we will introduce a new linux tool called Incron. It is similar to cron, but instead of running commands based on time, it can trigger commands when file or directory events occur. First of all, install incron using the command

sudo apt-get install incron

Before starting to use incrontab, we must give permissions for a user to use the service. To do this do:

nano /etc/incron.allow

and add the desired username to it.

Using incron is very much like using cron, ie. you can list, edit, and remove incrontab entries by using -l, -e and -r options, respectively. Have a look at the man page (man incrontab) for more options and the directions for usage.

man 5 incrontab will show the format of the crontabs we are going to create. Basically it is as follows:

path mask command

where path> can be a directory or a file that is watched. path> can be one of the following:

IN_ACCESS File was accessed (read) (*)
IN_ATTRIB Metadata changed (permissions, timestamps, extended attributes, etc.) (*)
IN_CLOSE_WRITE File opened for writing was closed (*)
IN_CLOSE_NOWRITE File not opened for writing was closed (*)
IN_CREATE File/directory created in watched directory (*)
IN_DELETE File/directory deleted from watched directory (*)
IN_DELETE_SELF Watched file/directory was itself deleted
IN_MODIFY File was modified (*)
IN_MOVE_SELF Watched file/directory was itself moved
IN_MOVED_FROM File moved out of watched directory (*)
IN_MOVED_TO File moved into watched directory (*)
IN_OPEN File was opened (*)

When monitoring a directory, the events marked with an asterisk (*) above can occur for files in the directory, in which case the name field in the returned event data identifies the name of the file within the directory.

Let’s create our first incron job. We’d like to monitor the directory /home/Downloads, and whenever a pdf file is downloaded into it, we want incron to activate a script that moves the file to another location. This is how we do it:

incrontab -e and put the following text into it.

/home/Downloads IN_CREATE /home/xxxx/.mvpdf.sh

Once the file is saved, type incrontab -l to see a list of incron jobs.

Test if everything is working as intended.

10
Jul

Malayalam Radio

Following is a link to a very nice online radio to listen to malayalm songs.

21
Jun

Custom .screenrc Configuration File

Screen may be the most useful Linux applications when it comes to getting things done through the terminal. This custom screenrc configuration file will provide you with a permanent caption line at the bottom of each window. This caption line will enable you to easily keep track of each terminal window and provide other helpful information such as host and current time.

When screen is invoked, it executes initialization commands from the files “/etc/screenrc” and “.screenrc” in the user’s home directory.

Simply create a file in your home directory with vim or some other editor.

$ vim ~/.screenrc

And place the following line in the file.

caption always "%{Wb} %H %{Bk}| %{Ck}%-w%50>%{Cb} %n %t %{-}%+w%<%{- Wk}%{Bk} | %=%{Wb} %C "

Now launch a new screen session for it to take effect.

6
Mar

Check Bandwidth Usage In Ubuntu

Install bwm-ng and/or iftop as given below:

sudo apt-get install bwm-ng
sudo apt-get install iftop

Enjoy!

9
Jun

Using Coral Draw Images In Ubuntu

Use uniconverter to convert .cdr file to any other format required.

Or use SK1 (http://sk1project.org/)

7
Jun

A Simple Script To Get A Terminal Dictionary

First, make sure that you have the Lynx web browser:

sudo apt-get install lynx

Now, make the following script:

#!/bin/sh

lynx -dump "http://wordnet.princeton.edu/perl/webwn?s=$1" | grep -B 1000 References | grep -A 1000 relations | less

Now you can define any word from the terminal. For example, suppose I want to know the definition of ‘psychoanalysis’, I can simply run:

./define psychoanalysis

and get the definition printed out.

It’s nothing fancy; just grabs the output from an online dictionary and spits it out to the terminal, but I find it to be very useful.

30
May

Free Up Cache Memory in Ubuntu

Ever wondered how to remove the cache memory in Ubuntu? Linux kernels 2.6.16 and newer provide a mechanism to clear the inode, page, and dentry caches on demand. All you have to do is echo a value to the proc filesystem, and you’re done. Follow the recipe below:

As this is a non-destructive operation and dirty objects are not freeable, run:
sync

To free pagecache:
sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"

To free dentries and inodes:
sudo sh -c "echo 2 > /proc/sys/vm/drop_caches"

To free pagecache, dentries and inodes:
sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"

Hope this works for you all.

26
May

How To Check Which Software Package Is Using More Space

If you’re running out of disk space and you want to quickly see what packages are using the most space on your hard drive, use the following command

dpkg-query --show --showformat='${Package;-50}\t${Installed-Size}\n' | sort -k 2 -n | grep -v deinstall | awk '{printf "%.3f MB \t %s\n", $2/(1024), $1}'

That will sort the packages by size, putting the largest ones on the bottom. If you only want to see the top few, you can type

tail -n 10

at the end, because in all likeliness you have a *lot* of packages installed

26
May

Using Terminal To Check The Size Of A Directory

You can also use a Terminal command to check the size of an individual directory. For instance, if you wanted to check the size of your Documents directory, you would use this command:

du -hs Documents

This will give you the combined size of your Documents folder, along with any subfolders.

14
May

Adding Public Key For Ubuntu Repositories

Following recipe will help to add a public key to ‘apt’ for repositories not already included in /etc/apt/sources.list. If you get an error ‘NO_PUBKEY XXXXXXXXXXXX’ , just use XXXXXXXXXXXX public key name in the following code.

gpg --keyserver hkp://subkeys.pgp.net --recv-keys XXXXXXXXXXXXXXXXX
sudo gpg --export --armor "XXXXXXXXXXXXXXXXXXX" | sudo apt-key add -
sudo apt-get update