Linux Most Used Commands

Hi, My name is Jimmy Sam. If you need DBA help, please email to jimmy_sam001@yahoo.com for further discussion. Thanks.
random password awk cut find sed sort
unix: wider screenn size
COLUMNS=380

top   prev   next  

screen

screen -S xxx    --> Create new screen window
screen -ls       --> list screen names
screen -x -r xxx --> attach
CTRL-a CTRL-d    --> detach
CTRL-a : fit ---> fit window
CTRL-a : quit ---> kill all windows and exit
screen ref1  screen ref2 
top
top   prev   next  

putty prompt

echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME} ${HOST} ${ORACLE_SID} : ${PWD} \007"'
echo $PROMPT_COMMAND

PS1="\[\u@\h: \w \s-\v\] \\$ "
PS1="\[\u@\h: \w \${ORACLE_SID} \s-\v\] \\$ "

top   prev   next  

check firewall

1): new way
sudo systemctl status firewalld
sudo service firewalld status
sudo firewall-cmd --state

# you can mask the firewall service which creates a 
# symbolic link of the firewall.service to /dev/null, 
# thus disabling the service.
#disable   systemctl mask firewalld
#re-enable systemctl unmask firewalld

2): old way
chkconfig --list
# chkconfig iptables off

cat /etc/sysconfig/iptables
iptables -L
iptables -L -n 
iptables -L -n -v
iptables -L -v -n --line-numbers

sudo iptables -L
sudo /sbin/iptables -L

service iptables status
# service iptables start
# service iptables stop

telnet hostname_or_ipaddress port

You can use the following two commands to get the cpu count and memory info

# -----------------------------------------------------------------------
cat /proc/cpuinfo|grep -i -c processor
cat /proc/meminfo|grep -i memtotal

cat /proc/cpuinfo
cat /proc/meminfo

# ----------------------------------------------------------------------

1): How to check Redhat Release
cat /etc/redhat-release
cat /etc/os-release

2): How to check kernel version
uname -r
uname -a
# - 3.10.0-957.el7.x86_64 #1 SMP Thu Oct 4 20:48:51 UTC 2018

2): get os pagesize
getconf PAGE_SIZE
4096

3):
# get user info
getent passwd oracle

# get group info
getent group dba

3): Check OS or Server Error Messages
/var/log/syslog
/var/log/messages

4):
/etc/fstab

/etc/mtab

5):
mount
mount|grep u1
cat /proc/mounts

6):
systemctl status sshd
# sudo systemctl start sshd
# yum install openssh-server

7): check firewall
systemctl status firewalld
#systemctl stop firewalld
#systemctl disable firewalld

# or if enabled
firewall-cmd –permanent –zone=public –add-port=1521/tcp
firewall-cmd –reload

# redhat 5 or 6
# service iptables stop
# chkconfig iptables off

8): SELINUX secured linux
cat /etc/selinux/config
# SELINUX=permissive
# SELINUX=disabled

9): kernel parameters
9a): query
# ls -l /proc/sys/kernel
sysctl kernel.shmmax
sysctl kernel.shmmni
sysctl kernel.shmall

# ls -l /proc/sys/fs

sysctl fs.file-max
sysctl fs.aio-max-nr

# ls -l /proc/sys/net/ipv4
sysctl net.ipv4.ip_local_port_range

# ls -l /proc/sys/net/core
sysctl net.core.rmem_max
sysctl net.core.wmem_max

9b) modify
#refresh or reload from file
# Read or query
/sbin/sysctl kernel.shmall

/sbin/sysctl -p
cat /etc/sysctl.conf

kernel.shmmni = 4096
kernel.shmmax = 4398046511104
kernel.shmall = 1073741824
kernel.sem = 250 32000 100 128

fs.aio-max-nr = 1048576
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586

kernel.panic_on_oops=1

10):
cat /etc/security/limits.conf
oracle   soft   nproc    131072
oracle   hard   nproc    131072
oracle   soft   nofile   131072
oracle   hard   nofile   131072
oracle   soft   core     unlimited
oracle   hard   core     unlimited
oracle   soft   memlock  50000000
oracle   hard   memlock  50000000
oracle   soft    stack   10240

11):
cat /etc/pam.d/login
session    required     pam_limits.so

12):
12aa): Install
# install missing software
yum install binutils -y
yum install compat-libstdc++-33 -y
yum install compat-libstdc++-33.i686 -y
yum install gcc -y
yum install gcc-c++ -y
yum install glibc -y
yum install glibc.i686 -y
yum install glibc-devel -y
yum install glibc-devel.i686 -y
yum install ksh -y
yum install libgcc -y
yum install libgcc.i686 -y
yum install libstdc++ -y
yum install libstdc++.i686 -y
yum install libstdc++-devel -y
yum install libstdc++-devel.i686 -y
yum install libaio -y
yum install libaio.i686 -y
yum install libaio-devel -y
yum install libaio-devel.i686 -y
yum install make -y
yum install sysstat -y
yum install unixODBC -y
yum install unixODBC-devel -y
yum install zlib-devel -y
yum install elfutils-libelf-devel -y

12ab):
rpm -Uvh elfutils-libelf-devel*.x86_64.rpm
rpm -Uvh libaio-devel*.x86_64.rpm
rpm -Uvh unixODBC*.x86_64.rpm
rpm -Uvh zlib-devel*.x86_64.rpm
# rpm -ivh zlib-devel-1.2.7-13.el7.x86_64.rpm
rpm -Uvh ksh*.x86_64.rpm
rpm -Uvh compat-libcap1*.x86_64.rpm
rpm -Uvh compat-libstdc++-33*.x86_64.rpm

12b): Query
rpm -q --qf '%{NAME}-%{VERSION}-%{RELEASE}(%{ARCH})\n' binutils \
elfutils-libelf \
elfutils-libelf-devel \
gcc \
gcc-c++ \
glibc \
glibc-common \
glibc-devel \
glibc-headers \
ksh \
libaio \
libaio-devel \
libgcc \
libstdc++ \
libstdc++-devel \
make \
sysstat \
unixODBC \
unixODBC-devel


13): Oracle Group
13a): Create Group
#groupadd -g 54321 oinstall
groupadd -g 203 dba
#groupadd -g 54323 oper
#groupadd -g 54324 backupdba
#groupadd -g 54325 dgdba
#groupadd -g 54326 kmdba
#groupadd -g 54327 asmdba
#groupadd -g 54328 asmoper
#groupadd -g 54329 asmadmin

13b): Query And Verify Group
sudo grep dba /etc/group
# dba:x:203:oracle

14): oracle User
14a): create user
useradd -g oinstall -G dba,oper oracle
#/usr/sbin/useradd -u 502 -g oinstall -G dba,oper oracle
/usr/sbin/useradd -u 502 -g dba -G dba oracle

14b): Verify user
sudo grep oracle /etc/passwd
oracle:x:202:203:Oracle User ID:/home/oracle:/bin/ksh

15): vi /etc/oratab
cat /etc/oratab
# bisq:/u01/oracle/ora11.203:N
# bisp:/u01/oracle/ora11.203:N

16):
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;

17):
# email test
echo "This is a test"|mail -S "Test For Email" mynclid@ncl.com

18):
# shared memory information
ipcs -m

19):
# acquire huge page memory
cat /proc/meminfo|grep -i HugePages_Total

20): X-Windows
20a): # testing on
xdpyinfo
20b): xming
X0.hosts: adding remote unix server name into this file before starting xmin

21): check Oracle Installation Options
select parameter, value from v$option order by 1;

# ---------- Softweare Version -----------------------------------------------
cat /etc/redhat-release

find / -name "lsb_release" -print 2>/dev/null

1):
uname -r
uname -m
uname -a

2):
# C Compile Version
gcc -v
gcc -v 2>&1 |tail -1

3):
C++ Compiler Version
g++ -v
g++ -v 2>&1 |tail -1

4):
Assembler
as -V
as -V 2>&1

5): Linker
ld -V
ld -V 2>&1 |head -1

6):
# java version
java -version



top   prev   next  

du -h order by size

du -a . | sort -n -r | head -n 10

find /u98 -xdev -type f -mtime -1 -size +10000k -ls | sort -n -k 7:
find . -maxdepth 1 -type f -exec du -h {} + | sort --human-numeric-sort --reverse
find . -maxdepth 1 -type f -exec du -h {} + | sort --human-numeric-sort

find /some/path -type f -printf '%s %p\n' | sort -rn
find . -type f -printf '%s %p\n' | sort -rn

top   prev   next  

df -h order by percent

df -h /u01 /u03 /u11 /u12 /u13 /u14 /u98 /u99

df -h|perl -pe "s/[ \t]+/ /g"|sort -n -k 5
df -h|perl -pe "s/[ \t][ \t]*/ /g"|sort -n -k 5

df -h|grep -i u03|perl -pe "s/[ \t][ \t]*/ /g"|sort -n -k 5

top   prev   next  

Merge Two Files Line By Line

paste -d'\0' a1.txt a2.txt 
paste -d'<' a1.txt a2.txt
paste -d'<' a1.txt a2.txt|sed 's/</ --< /g'
paste -d' ' a1.txt a2.txt
paste a1.txt a2.txt   --> default delimiter is tab

top   prev   next  

Shared Memory and Semaphore Segments

ipcs -b
ipcs -m
ipcs -s

# ipcrm -m 
# ipcrm -s 

top   prev   next  

Crontab output file with Date in File Name

# using the following command failed
* * * * * myprog > /dbbackups/rman_backup_`date '+%Y%M%d'`.log 2<&1

# using the following command will work 
* * * * * myprog > /u01/app/oracle/log/rman_backup_$(date +\%Y\%m\%d_\%H:\%M:\%S\%z).log 2<&1
* * * * * myprog > /u01/app/oracle/log/rman_backup_$(date +\%Y\%m\%d).log 2<&1

top   prev   next  

Environmental Variables Used By Oracle

ORACLE_BASE
ORACLE_HOME
ORACLE_SID
LD_LIBRARY_PATH
PATH
TMP=/tmp
TEMP=/tmp
TMPDIR=/tmp
ORACLE_PATH
SQLPATH
ORACLE_TERM
NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
TNS_ADMIN=$ORACLE_HOME/network/admin
ORA_NLS11=$ORACLE_HOME/nls/data
ORA_TZFILE=$ORACLE_HOME/oracore/zoneinfo/timezlrg.dat
ORAENV_ASK
ORACLE_TRACE=T  # If it is set to T, many Oracle shell scripts (eg: oraenv.sh) use the set -x command
export TWO_TASK=sid; sqlplus xxx/yyy
THREADS_FLAG=native
UMASK  # umask 022,  default file creation permission 644

CLASSPATH=$ORACLE_HOME/JRE
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib


top   prev   next  

Interact between sqlplus and shell

-- Passing sqlplus out to shell variable
VALUE=`sqlplus -silent "/ as sysdba" <<END
set pagesize 0 feedback off verify off heading off echo off
select max(sequence#) from v\\\$log_history;
exit;
END`

if [ -z "$VALUE" ]; then
    echo "No rows returned from database"
    exit 0
else
    echo "Max Sequence Number: $VALUE"
fi
-- Passing sql or sqlplus error code back to shell
sqlplus -s > junk1 "/ as sysdba" <<EOF
column num_tables new_value num_tables format 9999
select count(*) num_tables from dba_tables;
exit num_tables
EOF
echo "Number of tables: $?"

top   prev   next  
top

My Unix Environment

whoami  id   id -a
hostname
pwd
ls -lart

env|grep -i $HOME
env|grep -i oracle
alias

history|tail -n 10   -->  my last 10 commands

echo $SHELL          --> what is my shell
set -o|egrep "vi\W|emacs" --> what is editor for my shell

most used directories:
/root ---> root user's home directory
/db/q/sprn/v1/admin --> dbqsprn user's home directory

. --> current
.. --> parent

cd --> go to home directory
/  -> root directory

/etc
/root
/bin
/usr/bin
/usr/local/bin
$ORACLE_HOME/bin
/db/q/sprn/v1/product/11.2.0/bin
/db/q/sprn/v1/admin

userful commands:
find $ORACLE_BASE -name "alert*.log" -print
history|tail -n 10  --> my last 10 commands

sar

sar -ALL

cd /var/log/sa

-- previous day sar data
sar -f sa19
sar -f /var/log/sa/sa19


top   prev   next  

Environment Variables

env
env|sort
env|sort|more

env|grep -i oracle
env|grep -i oracle_sid
env|grep -i oracle_home
env|grep -i tns_admin
env|grep -i home
env|grep -i path
env|grep -i sqlpath


cd $HOME
cd ~
cd
cd ..
cd -
cd $ORACLE_HOME
cd $ORACLE_HOME/bin --> tnsping, sqlplus, lsnrctl
cd $ORACLE_HOME/dbs --> initSID.ora

cd $ORACLE_HOME/network/admin --> tnsnames.ora sqlnet.ora listener.ora
cd $TNS_ADMIN

cd $ORACLE_HOME/rdbms/admin   --> addmrpt.sql awrrpt.sql

pwd


top   prev   next  

very basic


set -o vi
set -o emacs
set -o|egrep "vi|emacs"
set -o|egrep "vi\W|emacs"

df -h
df -m
df -k

df -h /db/c/ntmk/v*

du -sh * 2>/dev/null

whoami
who am i
hostname
pwd

ps -ef|grep -i smon
ps -ef|grep -i $ORACLE_SID

top

man df
info df

-- --------------

cd /db/c/ntmk/v1/admin/NTMKC1/logs
pwd


ls -lart
ls -lart alert*.log

head -100  alert_NTMKC1.log
tail -100  alert_NTMKC1.log
more  alert_NTMKC1.log
vi    alert_NTMKC1.log

history

alias
alias alert

stty erase ^h

dbtest -sid inkd1
dbinfo -sid inkd1

in sqlplus, make sure you are in the right place:
select * from v$instance;
select * from v$database;
select user from dual;
!whoami
!hostname
!pwd
!ls -lart

top   prev   next  

More Complex

env|grep -i SQLPATH

export PATH=$PATH:$SQLPATH:.

1): using which,
short coming if the .sql file don't have the -x execute permissiojn, you can not find it

which as.sql
which ts_used.sql

2): using locate
locate ts_used.sql
locate as.sql

or
locate ts_used.sql|xargs ls -l
locate as.sql|xargs ls -l

top   prev   next  

sudo su - oracle

sudo su - oracle --> don't forget the - which will bring additional information

top   prev   next  

ls command

Turn off color Terminal
unalias ls

list files in different directories
ls -la /vol*/oradata/stage/.*orcl_idx_004.dbf

top   prev   next  

sed command

echo "This is a test"|sed 's/test/practice/'

echo "This is a test"|perl -p -i -e "s/test/practice/g"

For making the replacement in all files in the current directory, the following would be all that is needed:

perl -p -i -e "s/SHARK/DOLPHIN/g"  *


And then to search and make changes in files in the current and all sub directories:

find . -type f -print | xargs perl -p -i -e "s/SHARK/DOLPHIN/g"

top   prev   next  

awk command

#cutout the domain part of hostname
hostname|awk -F. '{ print $1 }'
hostname=`hostname|awk -F. '{ print $1 }'`

top   prev   next  

xargs command

echo /home/oraprd/auto_arch.9992|xargs rm -fr
find /home/oraprd/auto_arch.* type d -name "auto_arch.[0123456789]*" -mtime +1 -print 2>/dev/null|xargs rm -fr

top   prev   next  

find command

find . -name "*DBMS_AQ*" -print
find . -iname "*DBMS_AQ*" -print

10 days ago
find . -name "*.trc" -mtime +10 -exec ls -l {} \;
find . -name "*.aud" -mtime +80 -exec \ls -l {} \;

find . -name "*.trc" -mtime +10 -exec rm {} \;
find . -name "*.aud" -mtime +30 -exec \rm -f {} \;

10 minutes ago
find . -name "*.trc" -mmin +10 -exec ls -l {} \;
find . -name "*.trc" -mmin +10 -exec rm {} \;

-type and -print
find . -type f -name "*dmp.gz" -mtime +1 -print -exec ls -l {} \;
find . -type f -name "*dmp.gz" -mtime +1 -print -exec  rm -f {} \;

find . -name "*${ORACLE_SID}*arch*.arc" -mtime +80 -exec ls -l {} \;

find . -name "*${ORACLE_SID}*arch*.arc" -mtime +30 -exec \rm -f {} \;

top   prev   next  

cut

grep -i port|cut -d: -f2|cut -d' ' -f2`

top   prev   next  

file comparison

md5sum filename1
diff filename1 filename2

top   prev   next  

sort

sort -t: -n -k 1,1|tail -20
-t: seperator
-n: numeric
-r: reversal
-k: sort field
-u: sort unique    combine with diff command can find and/or eliminate duplicates: diff original sort_uniqued

top   prev   next  

ps long format

ps uxww
ps auxww|grep -i $USER
ps -Ao pid,args -ww

top   prev   next  

swap space Information

swapon -s
/sbin/swapon -s

cat /proc/meminfo
cat /proc/cpuinfo


top   prev   next  

Send Out Email

1): mailx -s "subject line" aaa.bbb@ccc.com,ddd.eee@fff.com < file1.txt

2): send as an attachment
uuencode file1.txt file1.txt|mailx -s "subject line" aaa.bbb@ccc.com,ddd.eee@fff.com

top   prev   next  

sshd ssh

SSHOpts="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -t"

ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -t

chkconfig sshd off
chkconfig sshd on

/sbin/chkconfig --list

service sshd stop
service sshd start

top   prev   next  

scp and rsync

# to local
rsync -avI --safe-links --del myusername@myhostname:/mydirectorypath/* .
rsync -avI                    myusername@myhostname:/mydirectorypath/* .

# to remote
rsync -auvzpogl -e ssh /u01/oracle/product/11.203 linux4:/u01/oracle/product/11.203

top   prev   next  

nslookup ifconfig ping

nslookup proddb002

/sbin/ifconfig

gui:
/usr/bin/system-config-network &


uhshen: --> . /u02/oracle/dba/hshen/users/my_alias.sh

-- ---------------
more my_alias.sh
cd /u02/oracle/dba/hshen/users
export HISTFILE=/u02/oracle/dba/hshen/users/.k
exec ksh
-- ---------------

alias fhh='alias|grep $1'
COLUMNS=350
set -o vi;

alias ls='ls -F'
alias lsd='ls -l|grep ^d'
alias rm='rm -i'
alias cp='cp -i'
alias sp='sqlplus "/as sysdba"'


OSTYPE=`uname -a|cut -d' ' -f1`
# echo $OSTYPE

if [[ "$OSTYPE" == "SunOS" ]];
then
         export HOSTNAME=`hostname`;
         stty sane
else if [[ "$OSTYPE" == "AIX" ]];
then
         export HOSTNAME=`hostname -s`;
else if [[ "$OSTYPE" == "Linux" ]];
then
         export HOSTNAME=`hostname -s`;
else
         export HOSTNAME=`hostname -s`;
fi
fi
fi

-- ------------------------------
function find_dot_file {
find /u02/oracle/shortcuts /u02/oracle/dbacommon /u02/oracle/menuscripts  -name $1 -print 2>/dev/null
find `echo $PATH|sed 's/:/ /g'` -name useap -print 2>/dev/null
}
-- ------------------------------



alias my_bdump='echo "column name format a21\ncolumn value format A80\nset line 180 trimspool on\nselect name,value from v\$parameter;"|sqlplus "/ as sysdba"|grep -i background_dump_dest|sed "s/background\_dump\_dest/cd/g"'
alias my_bdump2=`my_bdump`


'echo "column name format a21\ncolumn value format A80\nset line 180 trimspool on\nselect name,value from v\$parameter;"|sqlplus "/ as sysdba"|grep -i background_dump_dest|sed "s/background\_dump\_dest//g"|xargs cd'


top   prev   next  

vi takes out extra ^M

:%s/[ctrlkey+v and ctrl-key+M]//g
:%s/^V^M//g

# check free space in aix
# lsvg
rootvg
asdbvg

# lsvg asdbvg
# lsvg asdbvg|grep -i free

# df -h /backups
/dev/hd4           1.00      0.91    9%     4957     3% /

# lslv 
# lslv hd4
# lsattr -El hd4

# chfs -a size=+10000M /backups # Increase by 10GB


# lsattr -El hdisk2|grep queue_depth

# lsdev -Cc adapter
# lsdev -Cc adapter -spci | grep fcs

df -h
df -m
df -k

df -h /db/c/ntmk/v*


-- --------------

cd /db/c/ntmk/v1/admin/NTMKC1/logs
pwd


ls -lart
ls -lart alert*.log

head -100  alert_NTMKC1.log
tail -100  alert_NTMKC1.log
more  alert_NTMKC1.log
vi    alert_NTMKC1.log

history

alias
alias alert

stty erase ^h

-- --------------

dbtest -sid inkd1

dbinfo -sid inkd1

Turn off color Terminal
unalias ls


top   prev   next  

screen

screen -S xxx    --> Create new screen window
screen -ls       --> list screen names
screen -x -r xxx --> attach
CTRL-a CTRL-d    --> detach
CTRL-a : fit ---> fit window
CTRL-a : quit ---> kill all windows and exit
screen ref1 
screen ref2 

top
top   prev   next  

putty prompt

echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME} ${HOST} ${ORACLE_SID} : ${PWD} \007"'
echo $PROMPT_COMMAND

PS1="\[\u@\h: \w \s-\v\] \\$ "
PS1="\[\u@\h: \w \${ORACLE_SID} \s-\v\] \\$ "
top
top   prev   next  

My Unix Environment

#kill -9 pid, strip space for pid
ps -ef|grep -i ${ORACLE_SID}|grep -i escalate|sed 's/  / /g'|sed 's/  / /g'|sed 's/  / /g'|awk '{print "kill -9 " $2}'


grep -i CORRUPT alert_seap.log|cut -d' ' -f8|sort -u|wc -l

grep -i CORRUPT alert_seap.log|cut -d' ' -f8|sort -u|awk '{print mv $1 ../rat_bat}'

grep -i CORRUPT alert_seap.log|cut -d' ' -f8|sort -u|awk '{print "mv " $1 " ../rat_bad"}'

grep -i CORRUPT alert_seap.log|cut -d' ' -f8|sort -u|awk '{print "mv /u03/oracle/data/rat/" $1 " /u03/oracle/data/rat_bad"}'

whoami  id   id -a
hostname
pwd
ls -lart

topas --> top

env|grep -i $HOME
env|grep -i oracle
alias

history|tail -n 10   -->  my last 10 commands

echo $SHELL          --> what is my shell
set -o|egrep "vi\W|emacs" --> what is editor for my shell

most used directories:
/root ---> root user's home directory
/db/q/sprn/v1/admin --> dbqsprn user's home directory

. --> current 
.. --> parent
~  --> home directory
cd --> go to home directory
/  -> root directory

/etc
/root
/bin
/usr/bin
/usr/local/bin
$ORACLE_HOME/bin
/db/q/sprn/v1/product/11.2.0/bin
/db/q/sprn/v1/admin

userful commands:
find $ORACLE_BASE -name "alert*.log" -print
history|tail -n 10  --> my last 10 commands

sar 

sar -ALL

cd /var/log/sa

-- previous day sar data
sar -f sa19
sar -f /var/log/sa/sa19


top   prev   next  

Environment Variables

env
env|sort
env|sort|more

env|grep -i oracle
env|grep -i oracle_sid
env|grep -i oracle_home
env|grep -i tns_admin 
env|grep -i home
env|grep -i path
env|grep -i sqlpath


cd $HOME
cd ~
cd
cd ..
cd $ORACLE_HOME
cd $ORACLE_HOME/bin --> tnsping, sqlplus, lsnrctl 
cd $ORACLE_HOME/dbs --> initSID.ora

cd $ORACLE_HOME/network/admin --> tnsnames.ora sqlnet.ora listener.ora
cd $TNS_ADMIN

cd $ORACLE_HOME/rdbms/admin   --> addmrpt.sql awrrpt.sql

pwd


top   prev   next  

very basic


set -o vi
set -o emacs
set -o|egrep "vi|emacs"
set -o|egrep "vi\W|emacs"

df -h
df -m
df -k

df -h /db/c/ntmk/v*

du -sh * 2>/dev/null

whoami
who am i
hostname
pwd

ps -ef|grep -i smon
ps -ef|grep -i $ORACLE_SID

top

man df
info df

-- --------------

cd /db/c/ntmk/v1/admin/NTMKC1/logs
pwd


ls -lart
ls -lart alert*.log

head -100  alert_NTMKC1.log
tail -100  alert_NTMKC1.log
more  alert_NTMKC1.log
vi    alert_NTMKC1.log

history

alias
alias alert

stty erase ^h

-- --------------

dbtest -sid inkd1
dbinfo -sid inkd1

in sqlplus, make sure you are in the right place:
select * from v$instance;
select * from v$database;
select user from dual;
!whoami
!hostname
!pwd
!ls -lart

top   prev   next  

More Complex

env|grep -i SQLPATH

export PATH=$PATH:$SQLPATH:.

1): using which, 
short coming if the .sql file don't have the -x execute permissiojn, you can not find it

which as.sql
which ts_used.sql

2): using locate
locate ts_used.sql
locate as.sql

or
locate ts_used.sql|xargs ls -l
locate as.sql|xargs ls -l

top   prev   next  

sudo su - oracle

sudo su - oracle --> don't forget the - which will bring additional information

top   prev   next  

ls command

list files in different directories
ls -la /vol*/oradata/stage/.*orcl_idx_004.dbf

top   prev   next  

awk command

#cutout the domain part of hostname
hostname|awk -F. '{ print $1 }'
hostname=`hostname|awk -F. '{ print $1 }'`

top   prev   next  

xargs command

echo /home/oraprd/auto_arch.9992|xargs rm -fr
find /home/oraprd/auto_arch.* type d -name "auto_arch.[0123456789]*" -mtime +1 -print 2>/dev/null|xargs rm -fr 

top   prev   next  

find command

10 days ago
find . -name "*.trc" -mtime +10 -exec ls -l {} \;
find . -name "*.trc" -mtime +10 -exec rm {} \;

10 minutes ago
find . -name "*.trc" -mmin +10 -exec ls -l {} \;
find . -name "*.trc" -mmin +10 -exec rm {} \;

-type and -print
find . -type f -name "*dmp.gz" -mtime +1 -print -exec ls -l {} \;
find . -type f -name "*dmp.gz" -mtime +1 -print -exec  rm -f {} \;

top   prev   next  

cut

grep -i port|cut -d: -f2|cut -d' ' -f2`

file comparison

md5sum filename1 
diff filename1 filename2

top   prev   next  

sort

sort -t: -n -k 1,1|tail -20
-t: seperator 
-n: numeric
-r: reversal
-k: sort field
-u: sort unique    combine with diff command can find and/or eliminate duplicates: diff original sort_uniqued

top   prev   next  

ps long format

ps uxww 
ps auxww|grep -i $USER 
ps -Ao pid,args -ww

top   prev   next  

swap space Information

swapon -s
/sbin/swapon -s

cat /proc/meminfo
cat /proc/cpuinfo


top   prev   next  

Send Out Email

1): mailx -s "subject line" aaa.bbb@ccc.com,ddd.eee@fff.com < file1.txt

2): send as an attachment
uuencode file1.txt file1.txt|mailx -s "subject line" aaa.bbb@ccc.com,ddd.eee@fff.com

top   prev   next  

sshd ssh

chkconfig sshd off
chkconfig sshd on

/sbin/chkconfig --list

service sshd stop
service sshd start

top   prev   next  

scp and rsync

rsync -avI --safe-links --del myusername@myhostname:/mydirectorypath/* .
rsync -avI                    myusername@myhostname:/mydirectorypath/* .

top   prev   next  

nslookup ifconfig ping

nslookup proddb002

/sbin/ifconfig

gui:
/usr/bin/system-config-network &


top   prev   next  

radom password

1. 
date +%s | sha256sum | base64 | head -c 32 ; echo

2.
openssl rand -base64 6 
openssl rand -base64 8
openssl rand -base64 12 
openssl rand -base64 16 
openssl rand -base64 32

3. 
date | md5sum

4. using a website
random password
grc password

hpssacli - HP Smart Storage Adminstrator CLI

# hpssacli help
# hpssacli -h

hpssacli ctrl all show

hpssacli ctrl slot=0 pd all show

hpssacli ctrl slot=9 pd all show

output:
physicaldrive 3E:1:1 (port 3E:box 1:bay 1, SAS, 146 GB, OK)
physicaldrive 3E:1:2 (port 3E:box 1:bay 2, SAS, 146 GB, OK)
physicaldrive 3E:1:3 (port 3E:box 1:bay 3, SAS, 146 GB, OK)

-- notes: grep OK for disk status