Archive | August 2011

Change Runlevel of Process:Linux

“Runlevel” defines the state fo the machine after boot.

You can change the runlevel of the daemons i.e.processes using chkconfig command.

The command takes following runlevels:

Typical Linux runlevels:

Typical Linux runlevels
ID Name Description
0 Halt Shuts down the system.
1 Single-User Mode Mode for administrative tasks.
2 Multi-User Mode Does not configure network interfaces and does not export networks services.[4]
3 Multi-User Mode with Networking Starts the system normally.
4 Not used/User-definable For special purposes.
5 Start the system normally with appropriate display manager. ( with GUI ) As runlevel 3 + display manager.
6 Reboot Reboots the system.

Chkconfig command help:

chkconfig –help  or /sbin/chkconfg

List Runlevels of all processes:

sudo chkconfig –list

which will result into output similar to following image:

List Runlevels for a perticular process:

sudo chkconfig –list mysqld       –where mysqld is the process.

Changing RunLevels of a process:

sudo chkconfig –level 35 mysqld on

Here the runlevels 3 & 5 are usually set to autostart a process at startup & henc to avoid manual start i.e. by using sudo /etc/init.d/mysqld start

MySql:Create New User & Grant all Previleges to User.

First Login as Root:
mysql> mysql -u root -p

Then Creating New User(ex.ngs):
mysql> CREATE USER 'ngs'@'localhost' IDENTIFIED BY 'ngspass';

Then Provide the Permissions using following:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'ngs'@'localhost' WITH GRANT OPTION;

Show the List of Installed Packages:Linux

For Ubuntu:

The command we need to use is dpkg –get-selections, which will give us a list of all the currently installed packages.

$ dpkg –get-selections

To search for a particular package:

$ dpkg –get-selections | grep java

Here java is the package to be searched

To get the path of the package:

$ dpkg -L gcc


For Fedora/CentOS
You can use the query option in rpm e.g. to find all installed packages:
$ rpm -qa

To check a particular package:

$ rpm -qa | grep java


Install MySql in Ubuntu

MySQL database server is now owned by Oracle (formally Sun Microsystems) but can be installed using command line options without compiling anything under Ubuntu Linux. Open a terminal and type the following commands to upgrade package database:

sudo apt-get update

sudo apt-get upgrade

Install MySQL Server :

Type the following command to install latest stable MySQL server software:

sudo apt-get install mysql-server mysql-common mysql-client

If you want to reset root password from terminal use the following command:

/usr/bin/mysqladmin -u root  password  type_new_password_here

If it says Permissions Denied then try the above command with sudo keyword.

Then Restart the MySql Daemon by following command:

sudo /etc/init.d/mysqld restart

Setting Default Java as Sun JDK insted of Open JDK on Linux

OpenOffice package internally uses  Open JDK,but the OpenJDK is not suitable for compiling all java programs hence we should install & set the default Sun JDK‘s  Java Compiler.

Locate the Sun Java directory which is  usually present inside /usr/java  directory  & Enter following two commands just by replacing the directory path given in quotes.Here the Sun JDK version is 1.7,you may have different version between(1.4 to 1.7)

export JAVA_HOME=”/usr/java/jdk1.7.0″               ->  Home Dir path i.e. up to jdk1.7.0 directory

export PATH=”/usr/java/jdk1.7.0/bin:$PATH”          -> Bin Dir path i.e.upto bin folder

bash        ->To set the above variables

The Bin Directory contains the executables such as java ,javac etc..

Setting Path by editing the global config in /etc/profile OR /etc/bash.bashrc file for all users:

Just copy the above line i.e. export PATH=”/usr/java/jdk1.7.0/bin:$PATH” to the end of the files.

You can confirm the java version using the command on terminal :

java -version  or javac -version & try to compile & run simple java program like:

/* */

public class Hello


public static void main(String[] args)


System.out.println(“Hello world”);



Adding remote IP address to be accessed in Remote Hosts file

Use the following command on terminal:
sudo ssh-keygen -f “/root/.ssh/known_hosts” -R

Here “/root/.ssh/known_hosts” is a path where known hosts file exists,confirm by typing locate known_hosts is the IP address to be added in the file.

Installing Java (JDK & JRE) on Ubuntu

To install JDK on ubuntu first you’ll need to add Multiverse repository to /etc/apt/sources.list file

1)Edit the file using sudo vi /etc/apt/sources.list & copy these four lines at the end of the file.

deb hardy multiverse
deb-src hardy multiverse
deb hardy-updates multiverse
deb-src hardy-updates multiverse
Save this file.

2)sudo apt-get update

To install jdk & jre type following command in terminal:

3)sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk 

4)Check java version type;
java -version which should result like.

java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode)
Try - first java program
$ vi
Append code:
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");

Save and close the file. Compile and execute program by typing following two instructions:
$ javac
$ java HelloWorld

Hello, World!
%d bloggers like this: