Saturday, June 8, 2013

Basic Unix commands for Oracle DBAs

Basic Unix commands for Oracle DBAs

Get total RAM on the Linux system

Linux Operating System stores memory information in /proc/meminfo file.
cat /proc/meminfo
MemTotal: 16439648 kB
MemFree: 349904 kB
….
Linux free command takes information from meminfo file and prints it
free -k
total used free shared buffers cached
Mem: 16439648 15840476 599172 0 348872 11497768
-/+ buffers/cache: 3993836 12445812
Swap: 16779884 464 16779420

To get no of cpu in linux

cat /proc/cpuinfo|grep processor|wc -l
Linux Performance monitoring Commands are:
1) top
2) vmstat
3) sar

To get Disk/Filesystem space usage in Linux

df

It shows the available disk space.
Example.
$ df
$ df -k       (-k will show values in kilobytes)
$ df -kh      (-h print sizes in human readable format (e.g., 1K 234M 2G) )

set -o emacs

To enable UP arrow key and to get last command and command history for Oracle and other users use below command.
$ set -o emacs

cal

This command show a calendar for a specified month and/or year.
Example. To show this month’s calendar, enter:
$ cal
To show the twelve-month calendar for 2010, enter:
$ cal 2012
To show a calendar for just the month of May 2013, enter:
$ cal 5 2013

cat

This is one of the most flexible Unix commands. You can use to create, view and concatenate files.
Examples:
To create a file called test:
$ cat >test
To view a file use cat in a different way:
$ cat test
To write the contents of the file mytestfile to standard output with each line numbered:
$ cat -n mytestfile
To concatenate two files into one, files test1 and test2 and write the result to test.all use:
$ cat test1 test2 > test.all

cd

To change directory. Use this command to change directories.
Example:
To change to ORACLE_HOME directory enter:
$ cd /home/oracle/product/10g
$ cd $ORACLE_HOME
$ cd ~       Go back to home directory, useful if you’re lost.
$ cd ..       Go back one directory.

chmod

To changes the permissions on a file.
Example.
To change the permissions on file ‘test.txt’ to read only:
$ chmod 444 test.txt
chmod 600 {filespec} You can read and write; the world can’t. Good for files.
chmod 700 {filespec} You can read, write, and execute; the world can’t. Good for scripts.
chmod 644 {filespec} You can read and write; the world can only read. Good for web pages.
chmod 755 {filespec} You can read, write, and execute; the world can read and execute. Good for programs you want to share, and your public_html directory.

clear

This command clears the terminal screen.
Example.
To clear the terminal screen, enter
$ clear

cp

Use this to copy files.
Example.
To make a copy of the file ‘tnsnames.ora’ as ‘tnsnames_bkp.ora’:
$ cd /home/oracle/product/10g/network/admin
$ cp tnsnames.ora tnsnames_bkp.ora

date

Use this command to check the date and time.
Example.
$ date
Thu Mar 11 19:42:14 GMT 2010

echo

The echo command echoes its arguments. Use it to determine if certain environment variables are set. Precede the variable you would like to see by a dollar sign ($).
Examples:
To find out the location of the ORACLE_HOME or ORACLE_SID or PATH variable use:
$ echo $ORACLE_HOME
/home/oracle/product/10g
$ echo $ORACLE_SID
Ora10g
$ echo $PATH

find

Use this command to find a particular file or groups of files.
Examples.
To find the file initora10g.ora, you may use:
$ find / -name initora10g.ora -print
Modify the above command to search the current directory and its  subdirectories by replacing the slash with a period.
$ find . -name initora10g.ora -print
To list all files in your home directory by using the following:
$ find $HOME -print
To find  the location of tnsnames.ora use:
$ find / -name tnsnames.ora -print
To find the location of listener.ora use:
$ find / -name listener.ora -print
To find the location of alert.log file use:
$ find / -name alert*.log -print

grep

Use this command to search for information in a file or files.
Example:
To check the status of the Oracle PMON from the OS.
$ ps -ef | grep pmon
To get a list of process on the unix machine corresponding for a user. For example to list all running processes for oracle user on linux box
$ ps -ef| grep oracle
To to list all running processes for root user on linux box
$ ps -ef| grep root

hostname

Provides the hostname of the box you are currently working on. This is particularly useful when you have telnet sessions to several boxes at one time and when there is confusion as to which box you are currently on.
Example:
$  hostname
    Linux2

ls

This shows the contents of a particular directory.
Example:
cd /home/oracle/product/10g/bin
$ ls
$ ls –l
$ ls –ltr
$ ls -al
-l         detail listing of files
-t         sort by modification time
-r         reverse order while sorting
-a,        display all files( Use this to include hidden files. For Example .profile or .bash_profile )

man

Useful command that can help you figure out the syntax and purpose of most UNIX commands. Enter ‘man’ followed by the command you would like to execute, and you will get a quick rundown of what the command does and a description of how to use it.
Examples:
$ man ls         Displays details about the ls command.
$ man cat        Displays details about the cat command.
$ man chmod      Displays details about the chmod command.

mkdir

Use this command to create new directory.
Example:
To create a subdirectory in the home directory of your Unix account, use the mkdir command. For example, to create a subdirectory called Test, at the Unix prompt from within your home directory, enter.
$  mkdir test

more

Shows listing one screen at a time. More is a command used to read text files.
Example.
To see the page wise details of below files use the commands as mentioned below.
$ cd /home/oracle/product/10g/network/admin
$ more tnsnames.ora
$ more listener.ora
$ more sqlnet.ora

mv

Use this command to move or rename files.
Examples:
To rename the file ‘test.txt’ to ‘test.old’:
$ mv test.txt test.old
To move a file named Test from a subdirectory named my_new to another subdirectory named my_old , enter:
$ mv -i my_new/Test my_old

ps

To see list of all the operating system processes that are running.
Example:
$ ps
$ ps –ef|grep pmon

pwd

It means present working directory. Use this command to find out what directory you are working in.
Example.
$ pwd

setenv ( This command works on c shell only)

Use this command to set envirorment variables.
Example:
To change the default printer from hpx123 to myprinter:
$ echo $PRINTER
   hpx123
$ setenv PRINTER myprinter
$ echo $PRINTER
   myprinter
whatis – This command is used to get the definition or usage of any linux command.
Example:
$ whatis ls
$ whatis ps
$ whatis who

Miscellaneous Unix commands

chgrp – changes the group ownership of a file
chown – changes owner of file
r – To redo the last command typed. Useful when you have typed a long command and do not want to type the entire command again.
w – who is logged in, and what are they doing
wc – display a count of lines, words and characters in a file
which – locate a command; display its pathname or alias
who – who is on the system
whoami – display the effective current username
whois – Internet user name directory service
chsh -s {shell-name} {user-name} Command to change login shell in Linux / UNIX operating system
Example : chsh -s /bin/ksh  oracle
vi
The vi editor (short for visual editor) is a screen editor which is available on almost all Unix and Linux systems.

Vi has two modes insertion mode and command mode.
The editor begins in command mode, where the cursor movement and text deletion and pasting occur.
Insertion mode begins upon entering an insertion or change command.
[ESC] returns the editor to command mode (where you can quit, for example by typing :q!).
Most commands execute as soon as you type them except for “colon” commands which execute when you press the return key.

No comments:

Post a Comment