Common Unix Commands For DBA
These are the common UNIX commands that DBA's utilize during their everyday duties. A brief explanation of commands/examples is provided, however other options may be available, the man pages should be consulted for complete list of options.. The O'Reily Unix in a Nutshell is an excellent book, for other Unix Commands.
COMMAND USAGE DESCRIPTION
clear clear To clear the screen
ls ls [-options] [names]

List files. [names] if omitted, will list all files and subdirectories in the directory. Wild cards can be specified.

-l Long format listing (includes permissions, owner, size, modification time, etc.).

 

-a List all files, including the normally hidden . files.

 

-t List files according to modification time (newest first).

 

-r List files in reverse order (by name or by time).

 

-1 Print one entry per line of output.

 

-ltra List all files, in long format, in reverse order, by time.

 

man man [command] Provides Manual Pages for any UNIX command
pwd pwd Prints working/current directory name
cd cd [directory}

Change directory, without argument will change your working directory to your home

cd .. Changes to Directory above.

 

cd /tmp Changes to directory /tmp
mkdir mkdir directory

Create Directory

mkdir oracle Creates a directory called Oracle

 

mkdir -p /u01/app/oracle Creates the specified directory path in single command.
rmdir rmdir directory Remove directory
rm rm filename

Remove the specified file from the directory.

rm initALPHA.ora Removes file called initALPHA.ora
rm -i initTEST.ora Prompts user before removing file.
rm -rf /u01/app/test Remove directory with files. Important - There is no way to undelete a file or directory in UNIX. It is always good to have rm -i filename for deletes. N.B. There is no Recycle bin !!!!
cp cp file1 file2

Copies file from source to destination.

cp -r * /tmp To copy all files and subdirectories to /tmp, use -r, the recursive flag.

 

cp -i file1 file2 Prompts user for confirmations before copying file.
mv mv file1 file2

Moves files or directories from source to destination.

mv file1 dir1 Moves file1 to directory dir1

 

mv file1 dir1 /file2 Moves file1 to dir1/file2.
mv * dir1 Moves all files in current location to dir1
cat cat file1 List the contents of a file.
more more file1 Show the contents of the file, one page at a time. use space to see next page, q to quit.
page page file1 Show the contents of the file, one page at a time. use space to see next page, q to quit.
pg pg file1 To show the contents of the file, page by page. In pg, you go up and down the pages with + and - and numbers. 1= Page 1, $= Last page, -3= back 3 pages, +5= 5 pages forward, ENTER=next page, /Text= Search for Text, q = quit
head head [-x] file Displays first few lines of file, default is 10. head -20 displays 20 lines from top of file.
tail tail [+x] file Displays last few lines from end of file, head +20 displays 30 lines from end of file.
chown chown [-R] newuser file

Changes the owner of file. If -R used, change is applied to all files & directories recursively.      chown [-R] newuser:newgroup file1 changes owner& group of file1.

chgrp chgrp [-R] newuser file Changes the owner of file. If -R used, change is applied to all files & directories recursively.
find finds files on system

find searches recursively through the directory tree looking for files that match a logical expression.

find $HOME -print List all files (and subdirectories) in your home directory.

 

find /dba -name tspace.sql -print List all files named tspace.sql in the /dba directory
find /u01 -name '*.sql' -user oracle -print List "*.sql" files owned by oracle
compress `find . \! -name '*.Z' -print` Find and compress files whose names don't end with .Z

 

find / -size 0 -ok rm {} \; Remove all empty files on the system (prompting first
find /scripts -print | xargs grep 'tablespacl' Recursively grep for a pattern down a directory tree
find / -mtime -2 -print Search the system for files that were modified within the last two days
diff diff file1 file2 diff reports lines that differ between file1 and file2. Output consists of lines of context from each file, with file1 text flagged by a < symbol and file2 text, by a > symbol.
dircmp dircmp [-sd] dir1 dir2 The dircmp command examines dir1 and dir2 and generates various tabulated information about the contents of the directories. Specifying -d executes diff on files that are different, -s surpress messages about identical files.
echo echo string Prints the string to standard output . echo $ORACLE_HOME, displays content of variable.
grep grep [-X] regexp [files]

Search one or more files for lines that match a regular expression regexp.

-c Print only a count of matched lines

 

-i
Ignores case
-v
Print all lines that don't match regexp
grep -c /bin/ksh /etc/passwd List the number of users who use the Korn shell

 

grep -l '^#include' /usr/include/*
List header files that have at least one #include directive:

 

df df [-x]

Displays free space available on the system.

df [-x] [moutpoint] Displays freespace on mountpount.

 

df -k . Displays freespace in current mountpoint in Kilobytes
df -m . Displays freespace in current mountpoint in Megabytes ( Linux)
du du [-s] [dir1] Displays operating system blocks used. To convert to KB, for 512K OS blocks, divide the number by 2. If no directory is specified a summary of disk usage is given.
lp lp filename Spools file to default printer.
ps ps

process status - to list the process id, parent process, status etc. ps without any arguments will list current sessions processes.

ps -fu Full listing of my processes, with time, terminal id, parent id, etc.

 

ps -ef Full listing of all processed on the Unix Server.
/usr/ucb/ps -aux | more Displays the top ten processes on Server ( tested on solaris)
kill kill [-x] pid

Terminates or signals process.

kill 109012 Kills process 109012 (pid obtained from ps command)
kill -9 109012 To force termination of process id 109012
Kill %2 Kill background job 2.
who who -X

Shows users connected to system, the 'w' command gives similar information.

script script file Records commands and output to a file.
uname uname -a Displays basic systems information about system. e.g. hostname, os level, processor type.
hostname hostname Display current host. uname -n give silmilar information.
date date [-x] Displays date and time on server. date "+%m%d%Y" displays date in MM/DD/YYYY format.
cal cal 2001 display calender for year 2001
compress compress file Compresses file to filename.Z
uncompress uncompress file1.Z Uncompresses file file1.Z
nohup nohup command & no hangup - process does terminate even if the shell terminates.
& command & Runs commands (job) in background.
jobs jobs Displays current jobs running.
fg fg %1 to bring a background job to foreground
bg bg to put a job to the background. press ^Z, to suspend the process and then use bg, to put it in the background.
telnet telnet hostname Ppen a connection to another computer on the network. Alias name or IP address node can be specified.
ftp ftp hostname File Transfer Protocol - to copy file from one computer to another.
rcp rcp [-r] sourcehost:file1 destinationhost:file1 Remote copy. Copy files from one computer to another. The computers must have been configured to use rlogin.