Thursday, January 9, 2014

File compressions in Linux

1. tar command to make single archive file          
    tar -cvf testcontent.tar testcontent.txt          , tar -cvf  testcontent.tar yourFolder/

2. tar command to extract a tarball
    tar -xvf testcontent.tar

3. tar command to compress a file or folder with GZIP utility  
    tar -cvzf testcontent.tar.gz testcontent.txt    , tar -cvzf testcontent.tgz testcontent.txt

    Note : testcontent.tar.gz and testcontent.tgz are similar    

4. tar command to extract .tar.gz or .tgz file          
    tar -xvf testcontent.tar.gz                  , tar -xvf testcontent.tgz

5. tar command to compress a file or folder with BZ2 utility  
    tar -cvjf testcontent.tar.bz2 testcontent.txt  , tar -cvjf testcontent.tar.bz2 yourFolder/

6. tar command to extract .tar.bz2 file              
    tar -xvf testcontent.tar.gz

7. zip command to compress a file or folder          
    zip -r mybackupfile testfile.txt          , zip -r mybackupfile yourFolder/
    Note : Output file will be

8. zip command to uncompress a zip file            

Wednesday, January 8, 2014

How to run jar file in Linux

Goal :

 1. Most of production environments provides only terminal accesses. 
 2. Most of time there are no Graphical User Interfaces.
 3. So developers have to provide solutions  based on tiny console access. 
 4. Most of production environments are remotely located and support
     engineers  have to access them via slow network as well.


1. Install java and javac under Linux environment
2. Install Oracle under Linux environment
3. Download Oracle JDBC jar file from maven repository or oracle site.
    Ex - ojdbc14.jar


1. Create a simple project that connect to database and close the connection.
2. Export the project in to simple jar file.             
3. During this project we have to link Oracle JDBC driver jar file with the Project jar file.
4. Run the project jar file with making link to Oracle JDBC driver.

Step 1 : For the people who interested to write it from the scratch.
Navigate to Desktop by following command.
      cd ~/Desktop
Create folder called "testing" in your current location.
       mkdir testing
Change your directory to "testing"
       cd testing
Create folder called "javaunderlinux" inside folder called "testing"
       mkdir javaunderlinux
Step 2 : Create a class called "" inside folder called "javaunderlinux"
Use vi editor to create and save a java file.

Write your file as following manner.

package testing.javaunderlinux;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

class OracleTime{

     public static void main(String[] str){
        Connection dbConnection =  null;
       Statement statement = null;
       ResultSet rs = null;
          try {
        dbConnection =  DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","sys", "sys123");                                statement = dbConnection.createStatement();
                    rs=  statement.executeQuery("SELECT TO_CHAR(SYSDATE,'hh24:mi:ss') AS TIMENOW FROM DUAL");
                         System.out.println("Oracle Time : "+rs.getString("TIMENOW"));


           }catch ( Exception ex ){



Save and exit from

Step 3  : Time to compile
Go to the command prompt and change your directory to Desktop
      cd ~/Desktop
Then compile the code.
      javac testing/javaunderlinux/

Now it will create OracleTime.class inside folder called "javaunderlinux"

Step 4  : Creating jar file
Go to the command prompt and change your directory to Desktop
      cd ~/Desktop
Create jar file using following command.
      jar -cvf oracletime.jar testing/javaunderlinux/*
Step 5  : Time to run the jar file.

Check whether Oracle Database is up and running by following command.
      telnet localhost 1521

run the following command by linking both ojdbc14.jar and oracletime.jar
java -cp ojdbc14.jar:oracletime.jar testing.javaunderlinux.OracleTime

Step 6  : Time to see the result 

The result will similar to following one.
     Oracle Time : 16:45:22