UNIX & Linux For Oracle Developers & DBAs

General Information
Library Note Morgan's Library Page Header
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
Change user su
su
Change user sudo
sudo
Change Group ID groupmod -g <NEWGID> <GROUP>
usermod -u 100 oracle
groupmod -g 101 dba
find / -user 56 -exec chown -h 100 {} \;
find / -group 34 -exec chgrp -h 101 {} \;
usermod -g 101 oracle
List groups a user belongs to groups <user_name>
[root@oem13c2-demo-db18c etc]# groups ggate
ggate : oinstall
Change User ID usermod -u <NEWUID> <LOGIN>
See Change GROUP ID demo above
Change User ID id <user_name>
[root@oem13c2-demo-db18c etc]# id ggate
uid=1999(ggate) gid=54321(oinstall) groups=54321(oinstall)
Remove a user userdel -r <user_name>
[root@oem13c2-demo-db18c etc]# userdel -r ggate
Add an existing group to an existing user usermod <user_name> -g <group_name> -G <groups_list>
[root@oem13c2-demo-db18c etc]# usermod ggate -g dba -G oinstall
Note: After changing GID or UID be sure that you ...
 
Navigation
Present Working Directory pwd
pwd
Change Directory: Navigating from root cd <directory_name>
pwd

cd /etc

pwd
Change Directory: Navigating down one level pwd

cd pam.d

pwd
Change Directory ... up one level pwd

cd ..

pwd
Change To Root Directory cd /home/oracle

pwd

cd /

pwd
Change To A Directory with a dash in the name cd -- -MGMTDB

pwd
 
Navigation Demo
Navigation Exercise -- navigate to root directory
cd /

-- verify location
pwd

-- navigate to home directory
cd home

pwd

-- make a directory
mkdir  morgan

cd morgan

pwd

mkdir dest
mkdir src


ls -l

cd src

pwd

cd ../dest

pwd

cd ..

pwd
 
File Handling
Make Directory mkdir <directory_name>
ls -al

mkdir morgan

ls -al
Remove Directory rmdir <-options> <directory_name>
ls -al

rmdir morgan

ls -al
Remove Directory & Subdirectories rm -i <directory_name>
cd $HOME

pwd

ls -al

mkdir morgan

ls -al

cd morgan

pwd

mkdir subdir

ls -al

cd ..

pwd

rmdir morgan

rm -ir morgan

-- answer "y" (yes) to questions for removal to proceed
Create File touch <file_name>
cd $HOME

touch mlib.ora

ls -l
Copy cp <old_name> <new_name>
cp mlib.ora copiedfile.ora

ls -l *.ora
Recursive Copy (include directories and their contained files) cp -ir <old_name> <new_name>
cd /home/oracle

mkdir arch

cd arch

touch mlib.ora

cd ..

pwd

ls -l

cp -r arch /tmp

cd /tmp

ls -l
Secure CoPy scp <user_name>@<server_name>:<source_path_and_file_name> <target_path_and_file_name>
scp oracle@bigdog:/home/oracle/*.gz .
Delete (Remove) a file rm <file_spec>
touch delfile

ls -l

rm delfile
List ls [<-options>] <file_spec>
ls

ls *ora

ls -l *ora

ls -larn

ls -larnh *ora

ls -lt
List Reverse ls -r
ls -latr
List Extended Byte Group Names in AIX ls ls <file_space>
ls -lX
Move mv <starting_file> <resulting_file>
touch movefile

ls -l

mv movefile /home/movefile

ls -l 

cd /home

ls -l
Rename mv <starting_file> <resulting_file>
touch rename.txt

ls -l

mv rename.txt rename.log

ls -l
Wildcards: Multiple Characters *
touch test1
touch test2
mkdir arch

ls -l

mv test* arch

cd /arch

ls -l

rm t*

ls -l
Wildcard: Single Character ?
touch test1
touch test2
touch test99
mkdir arch

ls -l

mv test? arch

ls -l

cd /arch

ls -l

rm test?

ls -l
Change Owner chown <owner_name> <directory_or_file_name>
touch chngdemo

ls -al chngdemo

chown oracle chngdemo

ls -al chngdemo
Change Group chgrp <group_name> <directory_or_file_name>
touch chngdemo

ls -al chngdemo

chgrp dba chngdemo

ls -al chngdemo
Change Mode Triplets ROOT - GROUP - USER
drwxrwxrwx
Change Mode chmod <code> <file_name>
touch chngdemo

ls -al chngdemo

chmod 755 chngdemo

ls -al chngdemo
CHMOD and UMASK Codes and Results

First bit is '-' if a regular file
First triplet is owner
Second triplet is group owner
Third triplet is others
Binary Octal Permissions
000 0 ---
001 1 --x
010 2 -w-
011 3 -wx
100 4 r--
101 5 r-x
110 6 rw-
111 7 rwx
 
Code UMASK File Permissions Directory Permissions
111 666 ---------- ---x--x--x
222 555 --w--w--w- --w--w--w-
333 444 --w--w--w- --wx-wx-wx
444 333 -r--r--r-- -r--r--r--
555 222 -r--r--r-- -r-xr-xr-x
666 111 -rw-rw-rw- -rw-rw-rw-
777 000 -rw-rw-rw- -rwxrwxrwx
124 653 -----w-r-- ---x-w-r--
644 133 -rw-r--r-- -rw-r--r--
660 017 -rw-rw---- -rwxrw----
750 027 -rw-r----- -rwxr-x---
755 022 -rw-r--r-- -rwxr-xr-x
Setting the setuid bit chmod u<+ | ->s <file_name>
touch chngdemo

ls -al chngdemo

chmod u+s chngdemo

ls -al chngdemo
Setting the setgid bit chmod g<+ | ->s <file_name>
touch chngdemo

ls -la chngdemo

chmod g+s chngdemo

ls -al chngdemo
Setting the setoid bit chmod o<+ | ->s <file_name>
touch chngdemo

ls -la chngdemo

chmod o+s chngdemo

ls -al chngdemo
Symbolic changes

u = user
g = group
o = other
a = all
chmod o<+ | ->x <file_name>
touch chngdemo

ls -la chngdemo

chmod o+x chngdemo

ls -al chngdemo
 
Environment & Environment Manipulation
server uptime uptime
uptime
 15:29:26 up 236 days, 14:39, 1 user, load average 0.96, 1.04, 1.09
set the date and time date <-options>
date

date -s "20130703 23:59:00"
domain, dnsdomainname and hostname domainname
dnsdomainename
hostname
[opc@oem13c2-demo-db18c ~]$ sudo su -
[root@oem13c2-demo-db18c ~]# domainname
(none)
[root@oem13c2-demo-db18c ~]# dnsdomainname
compute-a430291.oraclecloud.internal
[root@oem13c2-demo-db18c ~]# hostname
oem13c2-demo-db18c
[root@oem13c2-demo-db18c ~]#
rename host server Rename a Linux server's name
su

cd /etc/sysconfig/network

-- change the HOSTNAME entry and reboot
List hardware/operating system environment uname <-options>
Switch Description
a all
i hardware platform
m machine name
n network node name
o operating system
p processor
r kernel release
s kernel name
v kernel version
uname -a

uname -i

uname -m

uname -o

uname -p

uname -r

uname -s

uname -v
View the full environment: All variables set
set

export ORACLE_SID=orabase

echo $ORACLE_SID

set
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

du -sH
du -sk
View environment variable's value echo <environment variable>
echo $ORACLE_SID
Find Files find . -name "<file_name>" -print
find * -name "crontab*" -print
Find Files Containing a String find * -type f -exec grep -l "<string>" {} \;
find * -type f -exec grep -l " dbms_appllication " {} \;
Find archive logs older than 3 days and delete them find
find . -name *.arc -type f -ctime +3 -exec rm {} \;
Delete files over 14 days old find <path> -name "<filemask>" -mtime+<days> -exec rm {}\;
find $WORKDIR -name "*.dat.*" -mtime + 14 -exec rm {} \;
Find and delete trace files more than 7 days old find . -name "<file_name>" -print
find $ORACLE_BASE/admin/$ORACLE_SID -name "*.trc" -mtime +7 -exec rm -f {} \;
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. */


[oracle@localhost jp]$ grep "THIS SCRIPT BELONGS TO ROAD FARMS COMPANY" *dat
[oracle@localhost jp]$

/* 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 $ grep "dbms_heat" /app/oracle/product/12.1.0/db_1/rdbms/admin/*
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
iostat [-x [INTEGER]]
iostat
Network Statistics ip <switches>
[root@ashoras1n1 etc]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      inet 127.0.0.1/8 scope host lo
      inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
      link/ether 00:17:a4:77:08:e4 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
      link/ether 00:17:a4:77:08:e4 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9000 qdisc pfifo_fast master bond1 qlen 1000
      link/ether 00:17:a4:77:08:e8 brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9000 qdisc pfifo_fast master bond1 qlen 1000
      link/ether 00:17:a4:77:08:e8 brd ff:ff:ff:ff:ff:ff
6: eth4: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9000 qdisc pfifo_fast master bond2 qlen 1000
      link/ether 00:17:a4:77:08:ec brd ff:ff:ff:ff:ff:ff
7: eth5: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 9000 qdisc pfifo_fast master bond2 qlen 1000
      link/ether 00:17:a4:77:08:ec brd ff:ff:ff:ff:ff:ff
8: eth6: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond3 qlen 1000
      link/ether 00:17:a4:77:08:f0 brd ff:ff:ff:ff:ff:ff
9: eth7: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond3 qlen 1000
      link/ether 00:17:a4:77:08:f0 brd ff:ff:ff:ff:ff:ff
10: sit0: <NOARP> mtu 1480 qdisc noop
      link/sit 0.0.0.0 brd 0.0.0.0
11: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue
      link/ether 00:17:a4:77:08:e4 brd ff:ff:ff:ff:ff:ff
      inet 10.20.70.11/24 brd 10.20.70.255 scope global bond0
      inet 10.20.70.102/24 brd 10.20.70.255 scope global secondary bond0:2
      inet 10.20.70.100/24 brd 10.20.70.255 scope global secondary bond0:3
      inet 10.20.70.10/24 brd 10.20.70.255 scope global secondary bond0:4
      inet6 fe80::217:a4ff:fe77:8e4/64 scope link
      valid_lft forever preferred_lft forever
12: bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9000 qdisc noqueue
      link/ether 00:17:a4:77:08:e8 brd ff:ff:ff:ff:ff:ff
      inet 10.20.72.10/24 brd 10.20.72.255 scope global bond1
      inet 169.254.85.254/16 brd 169.254.255.255 scope global bond1:1
      inet6 fe80::217:a4ff:fe77:8e8/64 scope link
      valid_lft forever preferred_lft forever
13: bond2: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 9000 qdisc noqueue
      link/ether 00:17:a4:77:08:ec brd ff:ff:ff:ff:ff:ff
      inet 10.20.254.26/24 brd 10.20.254.255 scope global bond2
      inet6 fe80::217:a4ff:fe77:8ec/64 scope link
      valid_lft forever preferred_lft forever
14: bond3: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue
      link/ether 00:17:a4:77:08:f0 brd ff:ff:ff:ff:ff:ff
      inet 10.24.50.20/24 brd 10.24.50.255 scope global bond3
      inet6 fe80::217:a4ff:fe77:8f0/64 scope link
      valid_lft forever preferred_lft forever
Processor lscpu
[root@ashoras1n1 etc]# lscpu

Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 8
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 79
Model name: Intel(R) Xeon(R) CPU E5-2680 v4@ 2.40GHz
Stepping: 1
Network Statistics netstat <switches>
[root@ashoras1n1 etc]# netstat -ie
Kernel Interface table
bond0 Link encap:Ethernet HWaddr 00:17:A4:77:08:E4
      inet addr:10.20.70.11 Bcast:10.20.70.255 Mask:255.255.255.0
      inet6 addr: fe80::217:a4ff:fe77:8e4/64 Scope:Link
      UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
      RX packets:25185522399 errors:0 dropped:0 overruns:0 frame:0
      TX packets:24064734199 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:5692092209185 (5.1 TiB) TX bytes:11665923311584 (10.6 TiB)

bond0:2 Link encap:Ethernet HWaddr 00:17:A4:77:08:E4
      inet addr:10.20.70.102 Bcast:10.20.70.255 Mask:255.255.255.0
      UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1

bond0:3 Link encap:Ethernet HWaddr 00:17:A4:77:08:E4
      inet addr:10.20.70.100 Bcast:10.20.70.255 Mask:255.255.255.0
      UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1

bond0:4 Link encap:Ethernet HWaddr 00:17:A4:77:08:E4
      inet addr:10.20.70.10 Bcast:10.20.70.255 Mask:255.255.255.0
      UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1

bond1 Link encap:Ethernet HWaddr 00:17:A4:77:08:E8
      inet addr:10.20.72.10 Bcast:10.20.72.255 Mask:255.255.255.0
      inet6 addr: fe80::217:a4ff:fe77:8e8/64 Scope:Link
      UP BROADCAST RUNNING MASTER MULTICAST MTU:9000 Metric:1
      RX packets:17757743639 errors:0 dropped:0 overruns:0 frame:0
      TX packets:34819528982 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:23877584376409 (21.7 TiB) TX bytes:131628535022044 (119.7 TiB)

bond1:1 Link encap:Ethernet HWaddr 00:17:A4:77:08:E8
      inet addr:169.254.85.254 Bcast:169.254.255.255 Mask:255.255.0.0
      UP BROADCAST RUNNING MASTER MULTICAST MTU:9000 Metric:1

bond2 Link encap:Ethernet HWaddr 00:17:A4:77:08:EC
      inet addr:10.20.254.26 Bcast:10.20.254.255 Mask:255.255.255.0
      inet6 addr: fe80::217:a4ff:fe77:8ec/64 Scope:Link
      UP BROADCAST RUNNING MASTER MULTICAST MTU:9000 Metric:1
      RX packets:510108433 errors:0 dropped:0 overruns:0 frame:0
      TX packets:434422536 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:2389898087115 (2.1 TiB) TX bytes:1188292531965 (1.0 TiB)

bond3 Link encap:Ethernet HWaddr 00:17:A4:77:08:F0
      inet addr:10.24.50.20 Bcast:10.24.50.255 Mask:255.255.255.0
      inet6 addr: fe80::217:a4ff:fe77:8f0/64 Scope:Link
      UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
      RX packets:8978409739 errors:0 dropped:0 overruns:0 frame:0
      TX packets:31196932293 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:575413126190 (535.8 GiB) TX bytes:47225801721209 (42.9 TiB)

eth0 Link encap:Ethernet HWaddr 00:17:A4:77:08:E4
      UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
      RX packets:25185305255 errors:0 dropped:0 overruns:0 frame:0
      TX packets:24064734199 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:5692065225406 (5.1 TiB) TX bytes:11665923311584 (10.6 TiB)
      Interrupt:114 Memory:fb000000-fb7fffff

eth1 Link encap:Ethernet HWaddr 00:17:A4:77:08:E4
      UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
      RX packets:217144 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:26983779 (25.7 MiB) TX bytes:0 (0.0 b)
      Interrupt:122 Memory:fa000000-fa7fffff

eth2 Link encap:Ethernet HWaddr 00:17:A4:77:08:E8
      UP BROADCAST RUNNING SLAVE MULTICAST MTU:9000 Metric:1
      RX packets:17757743529 errors:0 dropped:0 overruns:0 frame:0
      TX packets:34819528982 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:23877584354285 (21.7 TiB) TX bytes:131628535022044 (119.7 TiB)
      Interrupt:122 Memory:f9000000-f97fffff

eth3 Link encap:Ethernet HWaddr 00:17:A4:77:08:E8
      UP BROADCAST RUNNING SLAVE MULTICAST MTU:9000 Metric:1
      RX packets:110 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:22124 (21.6 KiB) TX bytes:0 (0.0 b)
      Interrupt:130 Memory:f8000000-f87fffff

eth4 Link encap:Ethernet HWaddr 00:17:A4:77:08:EC
      UP BROADCAST RUNNING SLAVE MULTICAST MTU:9000 Metric:1
      RX packets:508744710 errors:0 dropped:0 overruns:0 frame:0
      TX packets:434422536 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:2389794038847 (2.1 TiB) TX bytes:1188292531965 (1.0 TiB)
      Interrupt:130 Memory:f7000000-f77fffff

eth5 Link encap:Ethernet HWaddr 00:17:A4:77:08:EC
      UP BROADCAST RUNNING SLAVE MULTICAST MTU:9000 Metric:1
      RX packets:1363723 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:104048268 (99.2 MiB) TX bytes:0 (0.0 b)
      Interrupt:138 Memory:f6000000-f67fffff

eth6 Link encap:Ethernet HWaddr 00:17:A4:77:08:F0
      UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
      RX packets:8978065947 errors:0 dropped:0 overruns:0 frame:0
      TX packets:31196932293 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:575376058697 (535.8 GiB) TX bytes:47225801721209 (42.9 TiB)
      Interrupt:138 Memory:f5000000-f57fffff

eth7 Link encap:Ethernet HWaddr 00:17:A4:77:08:F0
      UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
      RX packets:343792 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:37067493 (35.3 MiB) TX bytes:0 (0.0 b)
      Interrupt:114 Memory:f4000000-f47fffff

lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING MTU:16436 Metric:1
      RX packets:8178619158 errors:0 dropped:0 overruns:0 frame:0
      TX packets:8178619158 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:7509666295015 (6.8 TiB) TX bytes:7509666295015 (6.8 TiB)
Ethernet Tool ethtool <eth#>
# ethtool eth2
TCP/IP packet analyzer examines packets being transmitted or received tcpdump -i <eth#>
# tcpdump -i eth2
More more <file_name>
cd /etc

more protocols
Processor related statistics mpstat -P ALL 12 5
-P is either calling out a specific processor or as in this example "all". The above is 12 second intervals and 5 reports in total
mpstat -P ALL 12 5
Display the Number of CPU cores nproc
[root@uw-orcl-4 ~] nproc
24
Processes ps <options> grep <filter>
ps -ef

ps -ef | grep ora
System Activity Statistics (Paging) sar <options>
sar -B
Tee

Splits the output of another command, sending it to a file and to the terminal.
tee <file_name>
cd $HOME

ls -larn

ls -larn | tee zzyzx

ls -larn

more zzyzx
Hard Link

A direct reference to an existing file
ln <path_and_name_to_source_file> <path_and_link_name>
ln sqlnet.ora protocol.ora
Soft (aka) Symbolic Link

Creates a pointer to a file that can cross file system boundaries
ln -s <path_and_name_to_source_file> <path_and_link_name>
ln -s /u01/app/oracle/21.1.0/db_home1/sqlnet.ora sqlnet.ora
Top CPU processes top
[root@db18c ~]# top
top - 00:52:58 up 75 days,  1:44,  1 user,  load average: 0.10, 0.13, 0.14
Tasks: 302 total,   1 running, 301 sleeping,   0 stopped,   0 zombie
Cpu(s): 0.3%us,  0.3%sy,  0.0%ni,  99.2%id,  0.1%wa,  0.0%hi,  0.0%si,  0.1%st
Mem:  15398260k total, 14775880k used,  622380k free,  744816k buffers
Swap:  4194300k total,   975428k used, 3218872k free, 3521088k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
20063 oraclet   -2   0 2329m  53m  52m S  1.3  0.4   1969:11 ora_vktm_orclt
 4620 root      20   0 3646m 305m  15m S  1.0  2.0 444:30.69 java
 1989 root      20   0 15212 2236 1756 R  0.7  0.0   0:00.09 top
20095 oraclet   20   0 2330m  68m  65m S  0.7  0.5 611:43.47 ora_lgwr_orclt
  596 oraclet   20   0 2358m 176m 163m S  0.3  1.2  20:49.78 ora_m006_orclt
 2815 oraclet   20   0 2343m  57m  54m S  0.3  0.4  31:17.37 ora_w003_orclt
 3386 oracle    20   0 5875m  58m  56m S  0.3  0.4  35:41.80 ora_scmn_orcl
 3394 oracle    20   0 5773m  78m  74m S  0.3  0.5 140:07.03 ora_dbrm_orcl
 3396 oracle    20   0 5756m  55m  55m S  0.3  0.4  90:29.03 ora_vkrm_orcl
10334 oraclet   20   0 2344m  77m  73m S  0.3  0.5  31:15.91 ora_w000_orclt
20085 oraclet   20   0 2329m  60m  58m S  0.3  0.4 246:04.56 ora_vkrm_orclt
20121 oraclet   20   0 2330m  89m  86m S  0.3  0.6  61:21.48 ora_mmnl_orclt
22077 oraclet   20   0 2343m  66m  63m S  0.3  0.4  32:08.95 ora_j004_orclt
32764 oracle    20   0 5817m 167m 124m S  0.3  1.1   5:49.43 ora_m002_orcl
    1 root      20   0 19408 2200 1972 S  0.0  0.0   1:55.76 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.20 kthreadd
    3 root      20   0     0    0    0 S  0.0  0.0   2:49.40 ksoftirqd/0
    5 root       0 -20     0    0    0 S  0.0  0.0   0:00.00 kworker/0:0H
    7 root      20   0     0    0    0 S  0.0  0.0  80:59.71 rcu_sched
    8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 rcu_bh
    9 root      20   0     0    0    0 S  0.0  0.0  46:38.57 rcuos/0
   10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 rcuob/0
   11 root      RT   0     0    0    0 S  0.0  0.0   0:14.91 migration/0
   12 root      RT   0     0    0    0 S  0.0  0.0   0:27.57 watchdog/0
   13 root      RT   0     0    0    0 S  0.0  0.0   0:25.52 watchdog/1
   14 root      RT   0     0    0    0 S  0.0  0.0   0:14.92 migration/1
   15 root      20   0     0    0    0 S  0.0  0.0   2:58.45 ksoftirqd/1
   17 root       0 -20     0    0    0 S  0.0  0.0   0:00.00 kworker/1:0H
   18 root      20   0     0    0    0 S  0.0  0.0  14:55.57 rcuos/1
   19 root      20   0     0    0    0 S  0.0  0.0   0:00.00 rcuob/1
   20 root      RT   0     0    0    0 S  0.0  0.0   0:36.06 watchdog/2
   21 root      RT   0     0    0    0 S  0.0  0.0   0:15.26 migration/2
   22 root      20   0     0    0    0 S  0.0  0.0   0:32.35 ksoftirqd/2
q
Top Swapping ordered by swap usage top
top
-- let to start ... then
Op<enter>
Free memory information

The m option display values in MB

Total = Total memory on system
Used = Used by Linux
free -m
opc@oem13c2-demo-db18c ~]$ free -m
             total      used      free     shared     buffers     cached
Mem:          7477      6811       666          1         199       2497
-/+ buffers/cache:      4113      3364
Swap:         4095       724      3371

[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
Swapping meminfo
[root@db18c ~]# cat /proc/meminfo
MemTotal:        15398260 kB
MemFree:           639436 kB
MemAvailable:     4086184 kB
Buffers:           744812 kB
Cached:           3520484 kB
SwapCached:        238004 kB
Active:           5300968 kB
Inactive:         1836356 kB
Active(anon):     3526820 kB
Inactive(anon):   1175688 kB
Active(file):     1774148 kB
Inactive(file):    660668 kB
Unevictable:            0 kB
Mlocked:                0 kB
SwapTotal:        4194300 kB
SwapFree:         3218872 kB
Dirty:                324 kB
Writeback:              0 kB
AnonPages:        2647644 kB
Mapped:           1862928 kB
Shmem:            1819892 kB
Slab:             1309324 kB
SReclaimable:     1265348 kB
SUnreclaim:         43976 kB
KernelStack:         6240 kB
PageTables:        184540 kB
NFS_Unstable:           0 kB
Bounce:                 0 kB
WritebackTmp:           0 kB
CommitLimit:      8907444 kB
Committed_AS:     7110872 kB
VmallocTotal: 34359738367 kB
VmallocUsed:        34132 kB
VmallocChunk: 34359698980 kB
HardwareCorrupted:      0 kB
AnonHugePages:    1576960 kB
CmaTotal:           16384 kB
CmaFree:                0 kB
HugePages_Total:     2916
HugePages_Free:       269
HugePages_Rsvd:         2
HugePages_Surp:         0
Hugepagesize:        2048 kB
DirectMap4k:        96256 kB
DirectMap2M:     15632384 kB
 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

16 = physical memory array
17 = memory device
dmidecode <shell command name>
[root@db18c ~]# sudo dmidecode -t 16
# dmidecode 2.12
SMBIOS 2.4 present.

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

[root@db18c ~]# sudo dmidecode -t 17
# dmidecode 2.12
SMBIOS 2.4 present.

Handle 0x1100, DMI type 17, 21 bytes
     Memory Device
     Array Handle: 0x1000
     Error Information Handle: 0x0000
     Total Width: 64 bits
     Data Width: 64 bits
     Size: 15360 MB
     Form Factor: DIMM
     Set: None
     Locator: DIMM 0
     Bank Locator: Not Specified
     Type: RAM
     Type Detail: None
View the full path of shell commands which <shell command name>
which grep

which id

which which
Subnet Masks CIDR

CIDR Subnet Mask Total IPs Usable IPs
32 255.255.255.255 1 1
31 255.255.255.254 2 0
30 255.255.255.252 4 2
29 255.255.255.248 8 6
28 255.255.255.240 16 14
27 255.255.255.224 32 30
26 255.255.255.192 64 62
25 255.255.255.128 128 126
24 255.255.255.0 256 254
23 255.255.254.0 512 510
22 255.255.252.0 1024 1022
21 255.255.248.0 2048 2046
20 255.255.240.0 4096 4094
19 255.255.224.0 8192 8190
18 255.255.192.0 16384 16382
17 255.255.128.0 32768 32766
16 255.255.0.0 65536 65534
15 255.254.0.0 131072 131070
14 255.252.0.0 262144 262142
13 255.248.0.0 524288 524286
12 255.240.0.0 1048576 1048574
11 255.224.0.0 2097152 2097150
10 255.192.0.0 4194304 4194302
9 255.128.0.0 8388608 8388606
8 255.0.0.0 16777216 16777214
7 254.0.0.0 33554432 33554430
6 252.0.0.0 67108864 67108862
5 248.0.0.0 134217728 134217726
4 240.0.0.0 268435456 268435454
3 224.0.0.0 536870912 536870910
2 192.0.0.0 1073741824 1073741822
1 128.0.0.0 2147483648 2147483646
0 0.0.0.0 4294967296 4294967294
 
System Management
Network Configuration ifconfig <options>
ifconfig
Wireless Configuration iwconfig <options>
iwconfig wifi0 power off
Shared Library Dependencies ldd <program_name>
ldd ???
Display Loaded Kernel Modules lsmod
lsmod
Display Open Files lsof
lsof
Display Formatted Process Tree pstree <options>
pstree -ca
 
User Management
Change Password and Expiration Information chage
chage ???
Force Password Change At Next Logon chage
chage -d0
Create Group groupadd <switch> <group_number> <group_name>
groupadd -g 500 oinstall
Group Delete groupdel <switch> <group_number> <group_name>
groupdel osdba
Display All Resource Limits for the Current User ulimit <switches>
ulimit -a
Display data about one or more users finger <switches> users
finger -l oracle
Remap key stty <keyword> <key>
stty ERASE <backspace_key>
-- displays stty ERASE ^?
 
vi Editor
create a new file or open a file for editing vi
vi initSID.ora
quit without saving :q!
:q!
save and quit :wq
:wq
insert Esc i
i
append Esc A
A
open a new line Esc o
o
replace a single character Esc r
r
replace multiple characters Esc R
R
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.
 
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

Related Topics
Cron Jobs