You are on page 1of 14

UNIX & Linux For Oracle Developers & DBAs Version 11.

1 General
Command Syntax Whatis

command [option] [source file(s)] [target file] whatis <command> whatis grep man man ls

Manual

man -k ls man -k ls | grep list

Directory Structure
Root /bin Commands that can be accessed by all users /boot Static boot loader files

/dev Device files /etc Host-specific configuration files /home User home directories /lib Shared libraries and kernel modules /mnt Mount point for temporary file systems /opt Add on application software /root Home directory for root user /sbin System binaries /tmp Temporary files /usr Shareable, read-only /var Variable data files User su <user_name>
Change User

su root su oracle exit exit

Become root

su su -

exit whoami
Current user account

whoami su whoami exit whoami

Navigation
Change Directory ... down one level Change Directory ... up one level Change To Root Directory

cd <directory_name> cd etc cd cd .. cd cd /

File Handling
Make Directory

mkdir <directory_name> mkdir morgan rmdir <directory_name> rmdir morgan rm -i <directory_name> cd $HOME ls -al mkdir morgan ls -al cd morgan mkdir subdir

Remove Directory

Remove Directory & Subdirectories

ls -al cd .. rm -ir morgan


Create File

touch <file_name> touch psoug.ora rm <file_name> rm psoug.ora cp <old_name> <new_name> cp psoug.ora / cp -i <old_name> <new_name> cp psoug.ora / cp -ir <old_name> <new_name> cp -ir psoug.ora / scp <user_name>@<server_name>:<source_path_and_file_name > <target_path_and_file_name> scp oracle@bigdog:/home/oracle/*.gz . rm <file_spec> touch delfile

Remove A File

Copy Copy with Confirmation Recursive Copy

Secure CoPy

Delete

ls -l rm delfile ls <switches> <file_spec> ls ls *ora

List

ls -l *ora ls -larn ls -larn *ora ls -lt mv <starting_file> <resulting_file>

Move

touch myfile

ls -l mv myfile /home/myfile ls -l mv <starting_file> <resulting_file> touch file1.aaa


Rename

ls -l mv file1.aaa file1.bbb ls -l * mv cp del ? mv

Wildcards: Multiple Characters

Wildcard: Single Character

cp del chown <owner_name> <directory_or_file_name> touch chngdemo

Change Owner

ls -l chown oracle chngdemo ls -l chgrp <group_name> <directory_or_file_name> touch chngdemo

Change Group

ls -l chgrp dba chngdemo ls -l

Change Mode

ROOT - GROUP - USER

Triplets

drwxrwxrwx chmod <code> <file_name> touch chngdemo

Change Mode

ls -l chmod 755 chngdemo ls -l


Code UMASK Result

CHMOD and UMASK Codes and Results

111 222 333 444 555 666 777 124 644 755

666 555 444 333 222 111 000 653 133 022

---x--x--x --w--w--w--wx-wx-wx -r--r--r--r-xr-xr-x -rw-rw-rw-rwxrwxrwx ---x-w-r----wr--r--rwxr-xr-x

Demo
Navigation Exercise

-- navigate to root directory cd / -- verify location pwd ls -l -- navigate to home directory cd home -- make a some directories mkdir morgan cd morgan pwd mkdir dest mkdir src

ls -l cd src pwd touch psoug ls -l mv psoug psoug.src mv psoug Environment Manipulation Rename a Linux server's name su
rename host server

cd /etc/sysconfig -- change the host name entry

uname

List hardware/operating system environment uname -a List environment variables for the current session Same as set. See export demo Sets environment variables set

env

export

export ORACLE_SID=orabase set

set

List environment variables for the current session Same as env. See export demo $HISTSIZE $HISTSIZE

command history

!10 !-4 $HISTSIZE=100

$HISTSIZE $HOME echo $HOME


command history

cd $HOME cd / cd ~

File Backup & Restore


Tape Archive (tar)

tar <switches> <file_spec> <tarball_name> tar -cvf * beta1RAC.tar tar <switches> <file_spec> <tarball_name> tar -cxvf * beta1RAC.tar.gz tar <switches> <file_spec> <tarball_name> tar -xvf beta1RAC.tar tar <switches> <file_spec> <tarball_name> tar -zxvf beta1RAC.tar.gz jar <switches> <file_spec> <jar_name> jar -xf patch.jar cpio -ivf <file_name> cpio -idv < as_linux_x86_101300_disk1.cpio

Compressed TAR

UNTAR UNTAR Compressed UNJAR A Java File CPIO

Cron Commands
crontab cronfile

Submits jobs to be scheduled ? Makes changes to an existing chron schedule ? Submits jobs to be scheduled ?

crontab -e

crontab cronfile

Applications
Concatenate (CAT)

cat <file_name> cat ?

An obscure word meaning "to connect in a series"

df <switches>
Disk Free Space

df -k df -m df -h (Linux only) echo <environment variable> echo $ORACLE_SID find . -name "<file_name>" -print find . -name "grep" -print find find . -name *.arc -type f -ctime +3 -exec rm {} \; find $WORKDIR -name "<filemask>" -mtime+<days> -exec rm {}\; find $WORKDIR -name "*.dat.*" -mtime + 14 -exec rm {} \; find . -name "<file_name>" -print find $ORACLE_BASE/admin/$ORACLE_SID -name "*.trc" mtime +7 -exec rm -f {} \; grep [-options] pattern [filename] grep iostat iostat more cd /etc more protocols

View environment variable's value Find Files Find archive logs older than 3 days and delete them

Delete files over 14 days old

Find and delete trace files more than 7 days old Global regular expression print (GREP). Prints all lines matching a certain pattern Disk i/o Memory Statistics

More

Processor related statistics

mpstat mpstat ps <switches> grep <filter> ps -ef ps -ef | grep ora

Processes

System Activity

sar

Statistics (Paging)

sar -B tee <file_name> cd $HOME

Tee Splits the output of another command, sending it to a file and to the terminal.

ls -larn ls -larn | tee zzyzx ls -larn more zzyzx top

Top CPU processes

top q

Virtual Memory Statistics

vmstat vmstat which <shell command name> which grep

View the full path of shell commands

which id which which

System Management
Wireless Configuration Shared Library Dependencies Display Loaded Kernel Modules Display Open Files Display Formatted Process Tree

iwconfig <switches> iwconfig wifi0 power off ldd <program_name> ldd ? lsmod lsmod lsof lsof pstree <switches> pstree -ca

User Management
Change Password

chage

and Expiration Information Force Password Change At Next Logon Create Group Display All Resource Limits for the Current User Display data about one or more users

chage ? chage chage -d0 groupadd <group_name> groupadd ulimit <switches> ulimit -a finger <switches> users finger -l oracle

vi
create a new file or open a file for editing quit without saving

vi vi initSID.ora :q! :q! :wq :wq Esc i i Esc A A Esc o o Esc r r Esc R R Esc x x Esc dd dd Esc dw

save and quit

insert

append

open a new line replace a single character replace a multiple character s delete a single character delete line delete word

dw
undo

Esc u u

SQL*Plus Shell Script Demo -- log onto Linux as the user oracle
bash demo

-- verify the UNIX user [oracle@gamma2 home]$ whoami oracle -- log into Oracle as scott/tiger [oracle@gamma2 ~]$ sqlplus scott/tiger@orcl SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 20 17:18:37 2006 Copyright (c) 1982, 2005, Oracle. reserved. All rights

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, Real Application Clusters, OLAP and Data Mining options -- create a test table SCOTT@orcl > create table test ( 2 testcol VARCHAR2(30)); Table created. -- exit SQL*Plus SCOTT@orcl >exit; [oracle@gamma2 ~]$Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Production With the Partitioning Option, Real Application Clusters, OLAP and Data Mining options -- verify location is Oracle's home directory [oracle@gamma2 ~]$ pwd /home/oracle

-- create a file named "morgan" [oracle@gamma2 ~]$ touch morgan -- look at the file's permissions [oracle@gamma2 ~]$ ls -al morgan -rw-r--r-- 1 oracle oinstall 0 Nov 20 15:56 morgan -- make it executable [oracle@gamma2 ~]$ chmod 755 morgan -- verify it is executable [oracle@gamma2 ~]$ ls -al morgan -rwxr-xr-x 1 oracle oinstall 0 Nov 20 15:56 morgan -- open the file using vi [oracle@gamma2 ~]$ vi morgan -- insert the following w/o quotes: "touch cline" -- verify the file's contents [oracle@gamma2 ~]$ more morgan touch cline -- execute it [oracle@gamma2 ~]$ ./morgan -- verify the cline file was created [oracle@gamma2 ~]$ ls -al cline -rw-r--r-- 1 oracle oinstall 0 Nov 20 16:04 cline -- delete the "cline" file [oracle@gamma2 ~]$ rm cline -- open morgan with vi, remove the TOUCH command -- and put in what you see after "more morgan" below [oracle@gamma2 ~]$ vi morgan [oracle@gamma2 ~]$ more morgan sqlplus scott/tiger@orcl <<EOF INSERT INTO test (testcol) VALUES ('Cline'); COMMIT; EXIT EOF -- execute it ... everything else is what scrolls on screen [oracle@gamma2 ~]$ ./morgan

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 20 17:20:16 2006 Copyright (c) 1982, 2005, Oracle. reserved. All rights

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, Real Application Clusters, OLAP and Data Mining options SCOTT@orcl > 1 row created. SCOTT@orcl > Commit complete. SCOTT@orcl > exit; Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, Real Application Clusters, OLAP and Data Mining options [oracle@gamma2 ~]$ Rescue boot: linux rescue
In the event of failure boot from the Linux CD or DVD

# chroot /mnt/sysimage # cd /boot/grub


use vi to edit/configure files

Example Configuration Files export DISPLAY=localhost:0:0


Export Display

echo $DISPLAY
.bash_profile

alias alias alias alias

ob='cd $ORACLE_BASE' oh='cd $ORACLE_HOME' cm='cd $ORACLE_HOME/oracm/log' sql='sqlplus "/ as sysdba"'

# Comment/Uncomment those entries for

hosts.equiv

your cluster below. alpha1 oracle alpha2 oracle #beta1 oracle #beta2 oracle #gamma1 oracle #gamma2 oracle delta1 oracle delta2 oracle alpha-node1 oracle alpha-node2 oracle #beta-node1 oracle #beta-node2 oracle #gamma-node1 oracle #gamma-node2 oracle #delta-node1 oracle #delta-node2 oracle # DO NOT Comment out this entry! topdog oracle

You might also like