Wednesday, September 30, 2009

Most usefull Linux command

Today i write most use-full linux command. I think this is most important for new linux users.

1. Copy command

$cp -irf source directory target directory

2. size

$du -sh direcotry name

3. Remove the diretory & subdirectory

$rm -irf directoryname

4. Move the files from one directory to another directory

mv -irf sourcedirectory targetdirectory

5. Change ownership on directory or subdirectory

$chown -R user:group directory

6. Find file in the linux system

$find -name eg: find /data1/PROD/ -name apichecb.pls

1. directory name where we want to search the file.

2. file name is which we want to search

7. How to check "File" type in linux

$file filename

8. how to check linux version
$uname -a

9. how to check group information in the linux

$cat /etc/group

10. how to install RPM package

#rpm -ivch packagename

i stand for install

11. change to usb filesystem type from ntfs to ext3

#mke2fs -j /dev/sdb1
then mount the usbfirst check the usb filesystem type

#fdisk -l then use the below command to mount

#mount /dev/sdb1 /mnt/usb

thanks for all



Thursday, September 10, 2009

Regular Expressions in MySQL

Introduction
A very interesting and useful capability of MySQL is to incorporate Regular Expressions (regex) in SQL queries. The regular expression support in MySQL is extensive. Let's take a look at using Regular Expressions in queries and the supported metacharacters.

Using Regular Expressions in queries
A simple example of using Regular Expressions in a SQL query would be to select all names from a table that start with 'A'.

eg:-
SELECT name FROM employees WHERE name REGEXP '^A'

A slight modification in the above example to look for names starting with 'A' or 'D' or 'F' will look like this.


eg:-
SELECT name FROM employees WHERE name REGEXP '^(A|D|F)'

Regular Expression Metacharacters
*
Matches zero or more instances of the string preceding it
+
Matches one or more instances of the string preceding it
?
Matches zero or one instances of the string preceding it
.
Matches any single character, except a newline
[xyz]
Matches any of x, y, or z (match one of enclosed characters)
[^xyz]
Matches any character not enclosed
[A-Z]

Matches any uppercase letter
[a-z]
Matches any lowercase letter
[0-9]
Matches any digit
^
Anchors the match from the beginning
$
Anchors the match to the end
|
Separates alternatives
{n,m}

String must occur at least n times, but not more than m times

{n}
String must occur exactly n times
{n,}
String must occur at least n times
[[:<:]]
Matches beginning of words
[[:>:]]

Matches ending of words

[:class:]
match a character class i.e.,
[:alpha:] for letters
[:space:]
for whitespace
[:punct:]
for punctuation
[:upper:]
for upper case letters

Examples

SELECT age FROM employees WHERE age REGEXP '^[0-9]+$'

/* starts, ends and contains numbers */

SELECT name FROM employees WHERE contact_no REGEXP '^[0-9]{10}$'

Thursday, September 3, 2009

How to install oci8(Oracle database) for php 5 and ubuntu 8.10

1. Install the Oracle Instant Client
  1. Download the Basic and SDK zip files from the official Oracle website.
  2. Create the following directory to store the instant client files
    /opt/oracle/instantclient/
  3. Unzip the basic.zip file into the above directory
  4. Create the following directory to store the sdk files
    /opt/oracle/instantclient/sdk/
  5. Unzip the sdk.zip file into the above directory
  6. Create the following two symbolic links
    1. ln -s libocci.so.11.1 libocci.so
    2. ln -s libclntsh.so.11.1 libclntsh.so

2. Install the oci8 module

For some reason on my system the automated build process failed.

This is an automated way of building and installing the module.

  1. Run the command to download and build the module
    sudo pecl install oci8
  2. When prompted enter the location of the instant client libraries
    instantclient,/opt/oracle/instantclient
  3. Congratulations, the library should now be installed
  4. Follow steps 14 and 15 to check that it is loading correctly. If it isn’t you may need to do steps 10 – 13 as well

If the automated script fails to find the instant client libraries follow this procedure

  1. Abort the automated build process Ctrl-C
  2. Change to the following directory
    /tmp/pear/download
  3. Copy the oci8-1.3.4.tgz to a suitable location, such as a sub directory in your home directory
    Note: the file name may be different depending on the version of the of the module
  4. Extract the contents of the file
    tar -xzf oci8-1.3.4.tgz
  5. Change into the new directory
    cd oci8-1.3.4
  6. Prepare the source code for building by executing this command
    phpize
  7. Configure the source code for building by executing the following command
    ./configure –with-oci8=shared,instantclient,/opt/oracle/instantclient
  8. Build the module by executing the following command
    make
  9. Install the newly built software
    sudo make install
  10. Change to the PHP 5 config directory
    cd /etc/php5/conf.d
  11. Open a new file in VI for editing
    sudo vi oci8.ini
  12. Add the following line to the file
    extension=oci8.so
  13. Write the file and quit VI
  14. Restart the Apache2 server
    sudo /etc/init.d/apache2 restart
  15. Check to ensure the module is loading using the phpinfo() function
thanks