Archive forLinux

Usefull vimdiff commands to view diff and merge

Diffing the files and merging them is one of the very common task we do everyday. Following are few very useful commands to view the diff using vim and merge them using the vimdiff commands instead of copying and pasting from one file to another.

To diff two files using vim :

vimdiff file1 file2
or
vim -d file1 file2

Ofcourse you can use gvim also but I don't prefer using GVIM.

gvimdiff file1 file2

Commands :

[c : Jump to previous diff
]c : Jump to the next diff

do or :diffget : Diff obtain (get the changes to the current buffer/file from the other buffer)
dp or :diffput : Diff Put (Put the changes from the current buffer/file to the other buffer)

As this being one of very command task I do, I have mapped them to single keys for the easy access.

nmap <F7> [czz
nmap <F8> ]czz
nmap <F2> do
nmap <F3> dp

The zz in the end of the command [c will center at the point of the diff so that we can view the diff clearly.

~Enjoy Vim

Comments

Sourcing a Shell script into perl

A lot of times we require to source the shell variables or shell script into the perl environment. One way to do this is you add very variable into the perl script something like :

$ENV{"SOME_VAR"} = "SOME_VAL";

The other best way to do this task is parse the shell file and source all the environment variables in to perl script environment. This way we don't need to modify your perl script every time the shell script is modified. :)

my ($envar, $enval);
open IN, ". ./3rdParty.env; env |"
or die "Could not run shell: $!\n";
while ( <IN> ) {
print $_;
chomp;
($envar,$enval) = split /=/,$_,2;
$ENV{$envar} = $enval;
}
close IN;

This is very useful if the shell script is changed very frequently by the users.

Comments

Changing Case in VIM

Sometimes we need to change the case of the letters in vim. Here is how you can do it with vim. Search and replace it with "\U&" or "\L&" or upper and lower letters.

changing to CAPITAL LETTERS :

:%s/^.*$/\U&/g

Changing to lower letters :

:%s/^.*$/\L&/g

Enjoy Power of VIM

Comments

LILO vs. GRUB

Two most popular boot loaders on linux systems are LILO and GRUB. If there are more then I dont know ;). First question is what is a boot loader ?

Boot loader loads the operating system to memory. When the system boots it reads the MBR(master boot record) of your system and You can store the boot record of only one operating system in a single MBR, so a problem becomes apparent when you require multiple operating systems. Hence the need for more flexible boot loaders and here comes LILO and GRUB in picture. Here are the main differences between these two.

  • LILO has no interactive command interface, whereas GRUB does.
  • LILO does not support booting from a network, whereas GRUB does.
  • LILO stores information about the location of the kernel or other operating system on the Master Boot Record (MBR). Every time a new operating system or kernel is added to the system, the Stage 1 LILO bootloader has to be manually overwritten, otherwise there is no way to boot the new OS or kernel. This method is more risky than the method used by GRUB because a mis-configured LILO configuration file may leave the system unbootable (a popular way to fix this problem is to boot from Knoppix or another live CD, chroot into the partition with mis-configured lilo.conf and correct the problem). On the other hand, correcting a mis-configured GRUB is comparatively simple as GRUB will default to its command line interface where the user can boot the system manually. This flexibility is probably the main reason why many users nowadays prefer GRUB over LILO.

Comments

Linux runlevels and boot process

I always see lots of directories in /etc/rc.d/ like rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6. Once I tried to find out what are all these. Then I came to know these are runlevels. Then the question came how do they get triggered and whats the difference between these runlevels. Here is what I found :

When you turn on the system following things happens :

1. Boot loader finds the kernel image from disk and loads it in to memory.

2. Kernel initializes the devices and its drivers

3. Kernel mounts the root file system

4. Kernel starts a program called init.

5. init start all the rest processes.

init

There is nothing special about init. It is a program just like any other on the Linux system, and you'll find it in /sbin along with other system binaries. The main purpose of init is to start and stop other programs in a particular sequence. All you have to know is how this sequence works.

Most linux system are System V (derived from AT&T System V) based . Another is based on BSD (Berkeley Software Distribution). What's the difference between the two? Basically BSD doesn't have any runlevels. This means that System V are more flexible

Most Linux distros put startup scripts in the rc subdirectories (rc1.d, rc2.d, etc.), whereas BSD systems house the system scripts in /etc/rc.d. Slackware's init setup is similar to BSD systems, though Slackware does have runlevels and has had System V compatibility since Slackware 7.

Runlevels :

At any given time on a Linux system, a certain base set of processes is running. This state of the machine is called its runlevel, and it is denoted with a number from 0 through 6. The system spends most of its time in a single runlevel.
You will also find a file named /etc/inittab. The system uses these files (and/or directories) to control the services to be started. If you look in the file /etc/inittab you will see something like:

id:5:initdefault:

l0:0:wait:/etc/rc.d/rc.0

l6:6:wait:/etc/rc.d/rc.6

x1:4:wait:/etc/rc.d/rc.4

First line means that the default runlevel on the system is 5. All lines in the inittab file take this form, with four fields separated by colons occurring in the following order:

  • A unique identifier (a short string, such as id in the preceding example)
  • The applicable runlevel number(s)
  • The action that init should take (in the preceding example, the action is to set the default runlevel to 5)
  • A command to execute (optional)
  • Run Level Generic Linux/Fedora Core Slackware Debian
    0 Halt Halt Halt Halt
    1 Single-user mode Single-user mode Single-user mode Single-user mode
    2 Basic multi-user mode (without networking) User definable (Unused) User definable - configured the same as runlevel 3 Multi-user mode
    3 Full (text based) multi-user mode Multi-user mode Multi-user mode - default Slackware runlevel
    4 Not used Not used X11 with KDM/GDM/XDM (session managers) Multi-user mode
    5 Full (GUI based) multi-user mode Full multi-user mode (with an X-based login screen) - default runlevel User definable - configured the same as runlevel 3 Multi-user mode
    6 Reboot Reboot Reboot Reboot

    Comments

    Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart the system.

    Sometimes when you try to start firefox, it gives error "Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart the system" and exits. This problem occur generally because of unclean shutdown or power reboots. Whenever we start firefox it creates a lock or .parentlock file in your firefox profile directory(~.mozilla/firefox/profile/.parentlock etc) and because of unclean shutdown not able to delete the file. This problem persists even if you try to reinstall the firefox.
    Simple solutions to this problem is remove the lock or .parentlock file :

    > rm -rf .mozilla/firefox/lprrz8oe.default/.parentlock or
    > rm -rf .mozilla/firefox/lprrz8oe.default/lock

    ENJOY BROWSING !!!!!

    Comments (3)

    How to start openoffice faster in linux

    I have a system with 1GB ram but the openoffice takes a long time to start up. Once I thought do some "googling and find out what is the solution to this problem.

    This is because by default the application only uses 9MB of the RAM for it's graphic cache. To increase the Graphic Cache, go to "Tools > Options > OpenOffice.org > Memory" and increase the "Graphics Cache" from 9M to about 128MB (or whatever you want). Restart OpenOffice and you will notice that the latency has now dissapeared.

    While you are at it, the Memory per object setting allocates memory for each object. The default is 2.4 MB which may need to be increased if you are working with high quality images or decreased if you are not really using images and you need to save on memory resources.

    Enjoy!!!!

    Comments

    "Quote of the Day"