ACE Director Alum Daniel Morgan, founder of Morgan's Library, is scheduling
complimentary technical Workshops on Database Security for the first 30
Oracle Database customers located anywhere in North America, EMEA, LATAM, or
APAC that send an email to
asra_us@oracle.com. Request a Workshop for
your organization today.
Command Syntax
command [option] [source file(s)] [target file]
Whatis
whatis <command>
whatis grep
Manual
man
man ls
man -k ls
man -k ls | grep list
Directory Structure
Basic directory structure of a UNIX or Linux file system
/
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
Change User
su <user_name>
su root
su oracle
exit
exit
Become root
su -
su -
exit
Current user account
whoami
whoami
su -
whoami
exit
whoami
Change password
passwd
passwd
-- you will be asked to enter your current password then twice enter the new password, identical in both character and case
List the environment of the current session: This is a more limited collection than is displayed by "set"
env
env
export CURUSER
echo $CURUSER
env
Remove an environment variable
unset <name>
set
unset CURUSER
set
profile
Set the environment and run the .profile commands
cd /home/oracle
-- use an editor to add the following to the .bash_profile file
export ZZYZX=$PATH
-- and save the file
more .bash_profile
echo $ZZYZX
source ~/.bash_profile
echo $ZZYZX
Command history
$HISTSIZE = <integer>
echo $HISTSIZE
!10
!-4
export
$HISTSIZE=100
echo
$HISTSIZE
Command prompt
-- bash
PS1=whoami@hostname\current working directory\time\date
-- korn
PS1='$PWD>'
Home environment variable
$HOME
cd /
pwd
echo $HOME
cd $HOME
pwd
cd ~
Rebooting
init <integer>
Level
Name
Description
0
Halt
Executes Shut Down
1
Single User
Administrative Tasks mode
2
Multi-User
Multi user without network interface or services configuration
3
Multi-User w/ Network
Normal system startup
4
Not Use / User Definable
-
5
Normal System Start
Run Level 3 plus display manager
6
Reboot
Reboots the system
# reboot
# reboot -f
# init 0
# init 6
Shutdown
shutdown -<switch>
Level
Description
h
Equivalent to init 0
r
Equivalent to init 6
-- shutdown then halt
# shutdown -h
-- reboot after shutdown
# shutdown -r
-- shutdown then power down
# shutdown -P
-- shutdown in 10 minutes
# shutdown +10
-- display the system shutdown entries and run level changes
# last -x | grep -e shutdown -r
File Backup & Restore
Tape Archive (tar)
tar <options> <file_spec> <tarball_name>
tar -cvf * beta1RAC.tar
Compressed TAR
tar <options> <file_spec> <tarball_name>
tar -cxvf * beta1RAC.tar.gz
UNTAR
tar <options> <file_spec> <tarball_name>
tar -xvf beta1RAC.tar
UNTAR Compressed
tar <options> <file_spec> <tarball_name>
tar -zxvf beta1RAC.tar.gz
UNJAR A Java File
jar <options> <file_spec> <jar_name>
jar -xf patch.jar
CPIO
cpio -ivf <file_name>
cpio -idv < as_linux_x86_101300_disk1.cpio
Cron Commands
Switch
Description
-e
Edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. After you exit from the editor, the modified crontab will be installed automatically.
-l
List - display the current crontab entries
-r
Remove the current crontab
Edit your crontab file, or create one if it doesn't already exist
crontab -e
crontab -e
Display the crontab file's contents
crontab -l
crontab -l
Remove the crontab file
crontab -r
crontab -r
Specify the crontab user
crontab -u <username>
crontab -u username -l
Display the last time the crontab file was edited (not on all systems)
crontab -v
crontab -v
Applications
Concatenate (CAT)
An obscure word meaning "to connect in a series"
cat [options] <file_name>
Switch
Description
A
show all
b
number non-blank lines
n
number all lines
s
squeeze blank: never more than one blank line
cd $ORACLE_HOME/network/admin
cat tnsnames.ora
cat -n tnsnames.ora
Disk Free Space
df <switches>
df
df -k
df -m
df -h (Linux only)
Disk Usage
du <switches>
Switch
Description
a
display an entry for each file contained in the current directory
c
display a grand total of the disk usage found by the other arguments
d #
the depth at which summing should occur. -d 0 = and the subdirectory level
H
calculate disk usage for link references specified at the command line
k
show sizes as multiples of 1024 bytes, not 512 bytes
L
calculate disk usage for link references anywhere
s
report only the sum of the usage in the current directory, not for each file
x
only traverse files and directories on the device on which the pathname argument is specified
Global Regular Expression Print (GREP). Prints all lines matching a certain pattern
Submitted to the library by JP Vijaykumar. Thank you.
grep [-options] pattern [filename]
-- I have the following files in a directory
[oracle@localhost jp]$ ls -l
total 48
-rwxrwxrwx 1 oracle oinstall 258 Aug 10 22:56 jp1.dat
-rwxrwxrwx 1 oracle oinstall 258 Aug 10 22:56 jp2.dat
-rwxrwxrwx 1 oracle oinstall 258 Aug 10 22:56 jp3.dat
-rwxrwxrwx 1 oracle oinstall 258 Aug 10 22:56 jp4.dat
-rwxrwxrwx 1 oracle oinstall 258 Aug 10 22:57 jp5.dat
/* I have to include the following message "THIS SCRIPT BELONGS TO ROAD FARMS COMPANY" in the third line of each of these files.
The redirection option ">>" can append the line to the end of a file. Let us see how to insert the message in the middle of a file.
I checked whether any of my files contain the message. */
/* I created a while loop to implement the task of copying the message in the middle of the files *.dat. */
[oracle@localhost jp]$ cat while_loop.sh
#!/bin/sh -x
#Author JP Vijaykumar Oracle DBA
#Date 08 - 08 - 08
#THIS SCRIPT INSERTS THE FOLLOWING MESSAGE
#IN THE THIRD LINE OF FILES *.DAT
#THIS SCRIPT BELONGS TO ROAD FARMS COMPANY
ls -1 |grep -v while_loop.sh|while read FILE
do
head -2 $FILE >> TEMP
echo "THIS SCRIPT BELONGS TO ROAD FARMS COMPANY" >> TEMP
tail -`cat $FILE|wc -l|awk '{print $0 -2}'` $FILE >> TEMP
mv TEMP $FILE
done
exit
-- I executed the script
[oracle@localhost jp]$./while_loop.sh
-- I checked whether any of my files contain this message
[oracle@localhost jp]$ grep "THIS SCRIPT BELONGS TO ROAD FARMS COMPANY" *dat
jp1.dat:THIS SCRIPT BELONGS TO ROAD FARMS COMPANY
jp2.dat:THIS SCRIPT BELONGS TO ROAD FARMS COMPANY
jp3.dat:THIS SCRIPT BELONGS TO ROAD FARMS COMPANY
jp4.dat:THIS SCRIPT BELONGS TO ROAD FARMS COMPANY
jp5.dat:THIS SCRIPT BELONGS TO ROAD FARMS COMPANY
Find a file containing a string recursing through subdirectories
[oracle@oem13c2-demo-db18c admin]$ grep -rn "lbac_exp" *
olse121.sql:98:-- Bug 23634413: Drop sys.lbac_exp package
olse121.sql:99:DROP PACKAGE sys.lbac_exp;
prvtolsdd.plb:159:CREATE OR REPLACE PACKAGE SYS.lbac_exp wrapped
prvtolsdd.plb:682:CREATE OR REPLACE PACKAGE BODY SYS.lbac_exp wrapped
prvtolsdd.plb:1053:GRANT EXECUTE ON sys.lbac_exp to PUBLIC;
Case insensitive find files containing a string and recurse through subdirectories
$ grep -ir "genserverinterface" *
CPU statistics and I/O statistics for devices, partitions, and network file systems
-x displays extended statistics
[INTEGER] repeat call every n seconds
[root@db18c ~]# free -m
total used free shared buffers cached
Mem : 15037 14412 625 1777 727 3435
-/+ buffers/cache: 10249 4787
Swap: 4095 952 3143
Virtual Memory Statistics
[root@db18c ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 975432 549324 744504 3518444 0 0 22 612 0 1 3 1 93 3 0
[root@db18c ~]# vmstat -s
15398260 total memory
14759356 used memory
5301472 active memory
1836220 inactive memory
638904 free memory
744816 buffer memory
3520844 swap cache
4194300 total swap
975428 used swap
3218872 free swap
75982150 non-nice user cpu ticks
1888 nice user cpu ticks
28240260 system cpu ticks
2358115135 idle cpu ticks
70056230 IO-wait cpu ticks
5016 IRQ cpu ticks
44720 softirq cpu ticks
1874270 stolen cpu ticks
559370116 pages paged in
15509984430 pages paged out
4640 pages swapped in
246914 pages swapped out
3274717629 interrupts
2044589083 CPU context switches
1529017730 boot time
32519633 forks
dumping a computer’s DMI (SMBIOS) contents in a human-readable format.
The output provides a description of the system’s hardware components, plus additional information such as serial numbers and BIOS revision. The information is not guarnateed reliable
Handle 0x1000, DMI type 16, 15 bytes
Physical Memory Array
Location: Other
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 15 GB
Error Information Handle: Not Provided
Number Of Devices: 1
replace multiple characters or a
string: case sensitive (default so I not required)
Esc :%s/<search string>/<replace_string>/gI
Esc :%s/stage/temp/g
replace multiple characters or a
string: case insensitive
Esc :%s/<search string>/<replace_string>/gi
Esc :%s/stage/temp/gi
delete a single character
Esc x
x
delete line
Esc dd
dd
delete word
Esc dw
dw
yank and put (copy and paste) text
Y
Yank the current line of text
yy
Yank the current line of text
yw
Yank word
y$
Yank to end of line
#Y
Yank multiple "#" lines
yG
Yank to end of file
p
Put after position
P
Put after line
undo
Esc u
u
SQL*Plus Shell Script Demo
bash demo
-- log onto Linux as the user oracle
-- 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. All rights reserved.
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 swartz"
-- verify the file's contents
[oracle@gamma2 ~]$ more morgan
touch swartz
-- execute it
[oracle@gamma2 ~]$ ./morgan
-- verify the swartz file was created
[oracle@gamma2 ~]$ ls -al swartz
-rw-r--r-- 1 oracle oinstall 0 Nov 20 16:04 swartz
-- delete the "swartz" file
[oracle@gamma2 ~]$ rm swartz
-- 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 ('Swartz');
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. All rights reserved.
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
In the event of failure boot from the Linux CD or DVD
boot: linux rescue
# chroot /mnt/sysimage
# cd /boot/grub
-- use vi to edit/configure files
Example Configuration Files
Export Display
export DISPLAY=localhost:0:0
echo $DISPLAY
.bash_profile
alias ob='cd $ORACLE_BASE'
alias oh='cd $ORACLE_HOME'
alias cm='cd $ORACLE_HOME/oracm/log'
alias sql='sqlplus "/ as sysdba"'
hosts.equiv
# Comment/Uncomment those entries for your cluster below.