Dreams of Thought

Are dreams thoughts… or are thoughts dreams..

RSS Feed

Archives for Linux

Installing Jetty on CentOS


Step 1 : Enable the jpackage repo Download the jpackage.repo file to your /etc/yum.repos.d/ directory.
# cd /etc/yum.repos.d/
# wget http://jpackage.org/jpackage50.repo

Step 2 : Install the jetty package you want
# yum search jetty
will show you a list of jetty packages you want to install. At the time of writing you get 2 options - jetty 5 and jetty 6. We installed jetty 6.
# yum install jetty6

Filed under Linux
Aug 29, 2012

Django 1.4 on CentOS 5.8


The default python version (2.4.3) on Centos 5.8 is not supported for Django 1.4 . Here's how to get Django 1.4 running on Centos 5.8 . Steps here are probably useful for future/different versions.

Step 1 : Enable EPEL

EPEL has newer version of Python available in it's repo. The first step is to enable it. The command you need to enable the EPEL repo is :
# rpm -ivh http://mirror.chpc.utah.edu/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
Once you install the package you've enabled EPEL.

Step 2 : Install Python 2.6 and easy_install

#yum install python26-distribute
This will install python 2.6 and easy_install

Step 3 : Install pip

#easy_install-2.6 pip
Now that you've pip installed, we can get started on install virtualenv and virtualenvwrapper.

Step 4 : virtualenv and virtualenvwrapper

#pip install virtualenvwrapper
will install virtualenvwrapper and virtualenv. Now you need to add some lines to your .bashrc
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python26
source /usr/bin/virtualenvwrapper.sh

(Make sure to create the ~/.virtualenvs directory if it isn't already created.)
Now activate the changes to your bashrc by doing
#source ~/.bashrc

Step 5 : Create a virtual environment for your Django project

You can do this by running
# mkvirtualenv my-env
Once you run this you will automatically switch to the new virtualenv. Your shell prompt will be prefixed with (my-venv)

Step 6 : Install Django

Change to the directory you want to install Django in. Then run :
(my-venv)#pip install Django


1. Installing MySQL-python :

First install
#yum install mysql-devel
and then install MySQL-python (my-venv)#pip install MySQL-python

2. Installing Gunicorn

(my-venv)#pip install gunicorn

3. requirements.txt

It's often easier to just have a list of pip packages to install for a particular project in a file. Conventionally, it's named requirements.txt
(my-venv)#pip install -r requirements.txt
will install all the packages given in the requirements.txt
(my-venv)#pip freeze
Will show you a list of packages installed by pip currently. Something like this :

You can take this list directly and put it into the requirements.txt
(my-env)# pip freeze > requirements.txt

Filed under django, Linux
Aug 24, 2012

apt-get with proxy


You will notice that the proxy settings you provide in the network settings may not be picked up by apt-get while installing a package. So if you want to run apt-get via a proxy then you need to use a tool like proxychains. Proxychains is a tool that allow you to run a command via a proxy even if the command itself does not support proxies. You can install proxychains by running apt-get install proxychains. In case this is not possible for you, then get the proxychains tarball from the proxychains site.Compile and install – it’s very simple to do. Just run ./configure and then make and make install. Run make install as root.

Once this is done you have proxychains installed in your system. Proxychains takes its settings from one of 3 files :

1)    ./proxychains.conf
2)    $(HOME)/.proxychains/proxychains.conf
3)    /etc/proxychains.conf

I edited the /etc/proxychains.conf file directly. I have a SOCKS5 proxy running on localhost over port 8080. So I add an entry towards the end like this -

socks5 8080

Once you have this and have your socks proxy running, you’re ready to start running your commands. Imagine you want to run apt-get update. This is how it would be done -

$ sudo proxychains apt-get upgrade

That’s it :)

Filed under Linux
Aug 1, 2011

vimdiff – the cool way to diff for vim users


Some of you using the vim editor may not know about a tool that comes with vim called vimdiff. Vimdiff is an awesome way to diff files if you are a vim nut. It gives you the power of vim + the power of diff.

How’s this different from opening 2 files in vim (with -O option) you ask ? The difference is that vim will highlight the diff for you.

Fire it up by giving the 2 filenames, say

$vimdiff old new

This will bring up a screen like this -



Now you can move around the 2 parts of the screen with your regular vim commands. For eg. use (Ctrl+w) + right arrow to move to the right half of the screen.

vimdiff with cursor on right half of screen

vimdiff with cursor on right half of screen

You can copy paste as well. Go to the 2nd line in the left half and press the y key twice to copy that line. Use (cntrl + w) + right arrow to move cursor to the 1st line in the right half of the screen. Press p to paste the copied line below the 1st line.

vimdiff with copy paste

vimdiff with copy paste

You can go to the first line and delete the two words “a new” by moving the cursor to “a” and hitting d2w key combo.

vimdiff deletes words

vimdiff deletes words

Insert “an old” there by going to insert mode(press i key) and then typing the two words. You’ll see that vimdiff does not highlight anything. This means that there is no difference between the two files.

two files with no difference in vimdiff

two files with no difference in vimdiff

Vimdiff is the same as bringing up vim with the -d option. You could do the same things you did above by using

$vim -d old new

Bonus :
You can also diff 2 URLs directly with vimdiff
$vimdiff 'http://www.google.co.in/search?q=vimdiff' 'http://www.google.co.in/search?q=vim'
You’ll first see something like this coming on screen

:!curl -o '/tmp/v959288/1' 'http://www.google.co.in/search\?q=vimdiff'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
"/tmp/v959288/1" 4L, 5289C
:!curl -o '/tmp/v959288/2' 'http://www.google.co.in/search\?q=vim'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
"/tmp/v959288/2" 4L, 5253C
Press ENTER or type command to continue

Now press the ENTER key to see the diff

vimdiff also works directly with URLs

vimdiff also works directly with URLs

You can throw in ssh into the mix as well. Try something like this
$vimdiff old <(ssh [email protected] cat ~/new)

If you're a vim/vimdiff ninja and know some more tricks, do post them below :)

Happy hacking...

Filed under Linux
Oct 20, 2009

Copy files preserving the permissions


You might have come across a situation where your regular usage of the cp command for copying files in your linux box was not enough because while copying you needed to preserve the permissions of the files. Fret not, for help is at hand. Take a look at the man page for cp :

-p     same as --preserve=mode,ownership,timestamps

--preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, all

So that’s it. just use the -p flag to do the copying. Here’s an example where I copy a single file while preserving permissions.

cp -p oldfile ~/new_dest/

To copy a whole directory, I use the -r flag as well.

cp -rp some_dir ~/new_dest/

You can use the –preserve flag to keep whatever attributes you need. For the record, there’s one more related flag

--no-preserve=ATTR_LIST don't preserve the specified attributes

Filed under Linux
Oct 1, 2009

Copying files from one unix box to another with scp


ssh is a very powerful and widely used protocol in all the Unices. If you’ve used the ssh client in your Unix/Linux box, you must have realised how indispensable it is. There is another indispensable tool that uses the ssh protocol – scp (secure copy). scp was meant to be an alternative to unsecure tools like rcp. It has since replaced most such programs. Since scp uses the ssh protocol, the encryption it uses ensures security of your data.

Using scp is simple. It works almost like the regular cp command. The basic syntax is
In order to specify the SOURCE or DESTINATION we have a special syntax.
[email protected]:PATH

Let me give you an example :
$scp [email protected]:/var/www/html/test.html [email protected]:~/test_dir/
Copy /var/www/html/test.html in the machine called “box” as user “anirudh” to the box called “linux” as user “gingerjoos” to the path HOMEDIR/test_dir/

That’s it :) Simple, right?

To copy the file to our localmachine, we could do this
$scp [email protected]:/var/www/html/test.html ~/workarea/

This would copy the file test.html in the machine called “box” (as user anirudh) to the localmachine at path HOMEDIR/work_area/

Interchange the source-destination to copy file in your localmachine to the remote machine.

If you want to copy whole directories, use the ‘-r’ flag(recursive copy)
$scp -r ~/workarea/ [email protected]:~/workdir/

Since scp is tied to the ssh program, the keys you use to set up passwordless login with ssh works for scp as well.

Got questions? Got something to add to this? Post your comments below :)

Filed under Linux, technology
Jul 31, 2009

How to join split files


This is sort of a follow-up to my previous post which talked about how you can use the split command in Linux to create split files which can be joined with hjsplit on Windows. My theory is that hjsplit does the same thing split does – which is just take the file and split it into the required number of pieces. No special headers or padding or compression or stuff. If that’s true, it should be easy as a pie to join the files split with hjsplit

To join files split with split, what I would do is use cat. Like this :
$cat xaa xab xac xad xae > debian-testing-i386-DVD-1.iso

Here xaa, xab, xac, xad and xae are the split files and debian-testing-i386-DVD-1.iso is the file after the join. I believe this should work fine for split files got from hjsplit too. Since I’m too lazy to go try it out in my friend’s Windows machine, I’ll leave it here at that. Do let me know if anyone’s tried it :)

Filed under Linux
Jun 24, 2009

hjsplit and linux split


The other day I had to fit in a 4.4 GB file (A Debian testing dvd iso image, if you want to know) on a 4 GB thumb drive. This, of course, is not possible. So I had to split the file into chunks, transfer them twice, take them to my friend’s windows machine and use hjsplit to join the files. How did I split the file so hjsplit could read it, when I didn’t use the linux version of hjsplit?

It looks like hjsplit splits its files by just cutting them into pieces. This is exactly what is done by the split command. Which is probably why I could use the linux split to split the file into a format hjsplit could join.

You could use a command similar to this one if you want to try it out :

$ split -b900M -d /home/anirudh/downloads/debian/debian-testing-i386-DVD-1.iso debian-testing-i386-DVD-1.iso.

the ‘-b’ option is used to specify the size of each chunk – 900 MB in this case. ‘-d’ means the output should be numeric (000,001,002…). Now we specify the large file and a prefix to attach to the generated filenames (note the dot at the end). This command will generate files :






Now this should be relatively easy to join with hjsplit. Do some renaming if required.


Edit :

meaculpa has noted that split starts renaming its files with 000 and not 001 as required by hjsplit. Please check his comment below for the solution.

As a follow up to this post, I had written another on how to join the split files in linux. You can check it out as well.

Filed under Linux
Jun 23, 2009

Useful vim commands


I use vim at work for most of my text editing purposes. Vim is a very powerful editor. However, it comes with a somewhat steep learning curve. The best place to learn it would be the vimtutor program. It’s got a pretty good “for dummies” approach which is useful if you haven’t used an editor even remotely powerful as this one before. If you’re short of time, the best way to learn it is to just jump in and start using it. Since it’s been around a long time, it has pretty much most features a developer needs. So if you have a need and don’t know how to get it done with vim, then use this site.

To start off using vim, let me give you a very quick and dirty first few steps. To open a file, simply use vim <filename>. You most likely have vi pointing to vim. Plus, most of these commands work with other vi’s anyway. So I’ll be using vi instead of vim henceforth.

Now that you have a file open, you would like to enter some stuff in? The basic thing you need to know about vi is that it has many modes. From the default mode(command mode) you need to press ‘i’ to enter the insert mode. In this mode you can type stuff in and it will show up on the screen. The command mode is where you issue commands to vi (But you can’t enter text). To go back from the insert mode to command mode press the escape key.

Now that you’ve typed some random stuff in, escape to the command mode. Now try pressing ‘:w’ i.e. (shift+;)w. W is for “write”. This saves the file and leaves you still in the editor. If you want to get out of the editor, you type in one more command ‘q’ so it becomes ‘:wq’. In case you want to get out of it without saving, use ‘:q!’. The other way to save and quit is to go to the command mode and hit shift+z+z.

With vi, the traditional way to navigate (in command mode) is to use l,k,j,h keys(right,up,down,left). That’s like the a,w,s,d in gaming. It’s a timesaver for people who are comfortable with it. Vim allows you to use the arrow keys as well, which is a real convenience.

That covers the bare minimum basics for us.

Once you start using vi you start looking for ways to accomplish tasks using it. There is a whole lot of material out there in the World Wide Web which will help you out. Google is your friend, use it :)

I will tell you some of the frequently used options/shortcuts I use with vim.

Going to a specific line : Type in ‘:25′ to go to line number 25 (in command mode). You can open a file at a specific line by typing

$ vi +25 FILENAME

This will open the file and take you to line 25. Now that you’re there, perhaps you would like to delete the next 5 lines? No problem – just hit d5d. The 5 in the middle says 5 and dd is for deleting lines. You will find this a common pattern with most vi commands. Just hitting dd will remove a single line. Similarly you can do d5w to remove 5 words and dw to remove a single word.

Copy paste is a walk in the  park. Hit y7y to copy 7 lines. Now press p to paste. That’s it. Cut paste? Hit d7d and then press p to paste after navigating to where you want to paste it.

The other approach to doing all this is to send a command. Hit ‘:201,225y’ to copy lines from 201 to 225. Similarly ‘:201,225d’ deletes lines from 201 to 225. To jump to a line you can use ‘:25′. This jumps to line number 25.

One useful shortcut when you don’t want to remember the line numbers is the use of markers. I can mark any 2 lines , say line numbers 201 and 225, and perform an action on them by using the name of the markers. Go to line number 201 and hit ‘ma’. This will mark that line with the marker ‘a’. Do the same with line 225 and mark it with ‘b’. Instead of uisng ‘:201,225d’ to delete lines 201 to 225, now you can use the a and b markers to delete the lines thus – “:’a,’bd”.

That was just a small snapshot of the commands that I use on vi. You can use a lot other features, like for instance macros, and enhance your editing experience. This should help you get started though. Let me know if this has been useful. Good luck and happy hacking :)

Filed under Linux, technology
Jun 4, 2009

Using Windows partitions from Debian GNU/Linux


My friend Arun recently blogged about Automounting filesystems in Linux from a Fedora perspective. For those of you who want an alternative method (especially Debian users), here goes…

I’ll explain how I did it – it’s much easier to understand from an example.

First of all, I used fdisk so I could know which were all the partitions in my system and what they were called.

debian-indraprastha:/home/anirudh# fdisk -l

Disk /dev/sda: 40.0 GB, 40060403712 bytes
255 heads, 63 sectors/track, 4870 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 1912 15358108+ c W95 FAT32 (LBA)
/dev/sda2 1913 3960 16450560 f W95 Ext’d (LBA)
/dev/sda3 3961 4870 7309575 83 Linux
/dev/sda5 1913 3187 10241406 b W95 FAT32
/dev/sda6 3917 3960 353398+ 82 Linux swap / Solaris
/dev/sda7 3188 3916 5855661 83 Linux

Now take the first entry. That partition is called /dev/sda1 and is the C: drive on Windows. Now I use the mount command to mount the partition. Mounting means that I attach a physical device to a directory, so that the directory itself becomes the device. It’s a concept that you get used to once you are familiar with all this. To mount the partition, I need a mount point. This is any directory that I create.

debian-indraprastha:/home/anirudh# mkdir /disks/c

Now I mount /dev/sda1 to /disks/c

debian-indraprastha:/home/anirudh# mount /dev/sda1 /disks/c

You can check if it has been mounted using the df command.

debian-indraprastha:/home/anirudh# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 6.9G 4.7G 1.9G 71% /
tmpfs 253M 0 253M 0% /dev/shm
/dev/sda5 9.8G 7.9G 1.9G 81% /disks/d
/dev/sda7 5.5G 4.6G 702M 87% /disks/s7
tmpfs 10M 716K 9.4M 7% /dev
/dev/sda1 15G 13G 2.4G 84% /disks/c

See the last entry? That shows that /dev/sda1 (the C: drive) has been mounted on /disks/c. Its total size is 15 GB of which 84%(13GB) has been used and 2.4GB is available.

Now there’s a file called /etc/fstab that comes in very handy. This mounting business is temporary. It gets “unmounted” after I shutdown. I would like to automatically mount it each time. I do that by modifying the /etc/fstab file. The /etc/fstab file keeps static information about the filesystems(refer $man fstab). Another file that comes in handy is /etc/mtab. This file keeps info about all the devices that have been mounted. After I mount /dev/sda1, an entry is made in /etc/mtab automatically.

/dev/sda1 /disks/c vfat rw 0 0

Now I copy this line into my /etc/fstab, with some modifications.

/dev/sda1 /disks/c vfat auto,exec,rw 0 0

Now each time the system boots, that drive will be mounted automatically.

Now, suppose I don’t want it to be mounted now? I use unmount.

debian-indraprastha:/home/anirudh# umount /dev/sda1

To disable the mounting of the paritition automatically, just remove that particular entry from /etc/fstab or uncomment it.

Have fun :-)

Filed under Linux, technology
Apr 5, 2007