Sie sind auf Seite 1von 11

Unix and AIX Commands for Basis and Oracle DBA consultant

This quick reference lists commands, including a syntax diagram and brief description. […] indicates an optional part of the command.
For more detail, use: man command

These command are more then enough for Oracle DBA and SAP BASIS Consultant. If you
can remember these commands then no need to refer any fat fat books of Unix and AIX.

1. Files
1.1. Filename Substitution
Wild Cards ?*
Character Class (c is any single character) [c…]
Range [c-c]
Home Directory ~
Home Directory of Another User ~user
List Files in Current Directory ls [-l]
List Hidden Files ls -[l]a

1.2. File Manipulation


Display File Contents cat filename
Copy cp source destination
Move (Rename) mv oldname newname
Remove (Delete) rm filename
Create or Modify file pico filename

1.3. File Properties


Seeing Permissions ls -l filename
Changing Permissions chmod nnn filename
Setting Default Permissions umask ugo
ugo is a (3-digit) number. Each digit restricts the default
permissions for the user, group, and others, respectively.
Changing Modification Time touch filename
Making Links ln [-s] oldname newname
Seeing File Types ls -F

1.4. Displaying a File with less


Run less less filename
Next line RETURN
Next Page SPACE
Previous line k
Previous Page b

1.5. Directories
Change Directory cd directory
Make New Directory mkdir directory
Remove Directory rmdir directory
Print Working (Show Current) Directory pwd

2. Commands
2.1. Command-line Special Characters
Quotes and Escape
Join Words "…"
Suppress Filename, Variable Substitution '…'
Escape Character \
Separation, Continuation

Command Separation ;
Command-Line Continuation (at end of line) \
2.2. I/O Redirection and Pipes
Standard Output >
(overwrite if exists) >!
Appending to Standard Output >>
Standard Input <
Standard Error and Output >&
Filters
Word/Line Count wc [-l]
Last n Lines tail [-n]
Sort lines sort [-n]
Multicolumn Output pr -t
List Spelling Errors ispell
2.3. Searching with grep
grep Command grep "pattern" filename
command | grep "pattern"
Search Patterns
beginning of line ^
end of line $
any single character .
single character in list or range […]
character not in list or range [^…]
zero or more of preceding char. or pattern *
zero or more of any character .*
escapes special meaning \

3. C-Shell Features.
3.1 History Substitution
Repeat Previous Command !!
Commands Beginning with str !str
Commands Containing str !?str[?]
All Arguments to Prev. Command !*
Word Designators
All Arguments :*
Last Argument :$
First Argument :^
n'th Argument :n

4. Processes
Listing ps [-[ef]]
Terminating kill [-9] PID

5. Users
Seeing Who is Logged In who
Seeing Your User Name whoami

6. Managing Files
6.1. Looking Up Files
Standard Commands whereis file
Aliases and Commands which command
Describe Command whatis command
Searching Out Files find dir -name name -print
dir is a directory name within which to search.
name is a filename to search for.
6.2. Finding Changes
Comparing Files diff leftfile rightfile
diff prefixes a less-than (<) to selected lines from leftfile
and a greater-than (>) to lines from rightfile.
6.3. Managing Disk Usage
Check Quota quota -v
Seeing Disk Usage df
du -s
6.5. Combining and Compressing Files
Create a tarfile tar cf file.tar file1 file2 … fileN
tar combines files but does not compress
Create a zipfile zip filename
Unzip a file unzip filename

Common UNIX Commands


These are the common UNIX commands Oracle DBAs would use. I have provided brief explanation of
commands and examples. In UNIX, most commands have a lot of options available. For a complete list of
options, see the UNIX online manual pages. All UNIX commands and file names are case sensitive. This
page is to let you know the commands in UNIX, which might give you a start to learn more about the
command using the manual pages or from UNIX books.

man man command Manual Pages - Help with any UNIX command
man ps Help on the UNIX ps command

clear clear To clear the screen

pwd pwd Present / Current Working Directory

cd cd Change directory, without argument will


[directoryname] change your working directory to your home
directory.
cd work Change working directory to "work"

cd .. Change working directory to parent directory


(.. is parent and . is current directory)
ls ls [- List files. [names] if omitted, will list all files
options] and subdirectories in the directory. Wild cards can
[names] be specified.
ls -l List files with date and permissions
-rw-rw-r-- 1 oracle dba 706 Sep 23 17:26
storparms.sql -rwxrwx--- 1 oracle dba 377 Aug 28
15:00 sysdelstat.sql drwxrwxr-- 2 oracle dba 2048
Oct 22 16:12 work
[column1] [2] [3] [4] [5] [6] [7]
Column1 - Permissions of the file or directory; r-
read, w-write, x-execute
Position 1 indicates if it is a directory
Positions 2-4 is the permission for owner
Positions 5-7 is the permission for group
Positions 8-10 is the permission for others
Column2 - Owner of the file/directory
Column3 - Group which the owner belogs to
Column4 - Size of the file in bytes
Column5 - Last Modified Date
Column6 - Last Modified Time
Column7 - Name of the file/directory
ls -al List files with date and permissions including hidden
files
ls -lt List files with date, sorted in the date modified

ls -ltr bt* List files with date, sorted in the date modified,
oldest first, with filenames starting with bt
Wildcards * Any character, any number of positions
? Any character, one position

[] A set of characters which match a single


character position.
- To specify a range within []

ls *x* List all files which contains an x in any


position of the name.
ls x* List all files which start with x

ls *T0[1-3]ZZ List all files which contain T0 followed by


1,2 or 3 followed by ZZ. The following
files match this condition:
analyzeall.AAAT01ZZ
dbaoc_err.AAAT03ZZ
dbstart_log.AAAT03ZZ
calerterr.AAAT01ZZ
dbaoc_log.AAAT01ZZ
ls job?.sql List files which start with job followed by
any single character followed by .sql
Example: jobd.sql jobr.sql
ls alert*.??? alert_AAAT01ZZ.1019
[0-1,9] alert_AAAD00ZZ.1020
alert_AAAI09ZZ.1021

touch - touch filename Create a 0 byte file or to change the


timestamp of file to current time (wild
cards as above can be used with the file
names)

mkdir mkdir Create Directory


directoryname
mkdir -p directorypath Create directory down many levels in single
pass
mkdir -p /home/biju/work/yday/tday
rmdir rmdir directoryname Remove directory

rm rm filename Remove file


rm -rf directoryname Remove directory with files.
Important - There is no way to
undelete a file or directory in
UNIX. So be careful in deleting
files and directories. It is always
good to have rm -i filename for
deletes

cp cp filename newfilename Copy a file


cp -r * newloc To copy all files and
subdirectories to a new location,
use -r, the recursive flag.

mv mv filename newfilename Rename (Move) a file. Rename


filename to newfilename.
mv filename directoryname Move filename under directoryname
with the same file name.
mv filename Move filename to directoryname as
directoryname/newfilename newfilename.
mv * destination If you use a wildcard in the
filename, mv catenates all files to
one sigle file, unless the
destination is a directory.
cp -i file1 file2 Use the -i flag with rm, mv and cp
mv -i file1 file2 to confirm before destroying a
rm -i file* file.
file file filename To see what kind of file, whether
editable. Executable files are
binary and you should not open
them.
file d* dbshut: ascii text
dbsnmp: PA-RISC1.1 shared
executable dynamically linked -not
stripped
dbstart: ascii text
dbv: PA-RISC1.1 shared executable
dynamically linked -not stripped
demobld: commands text
demodrop: commands text

vi vi filename Edit a text file. Vi is a very


powerful and "difficult to
understand" editor. But once you
start using, you'll love it! All
you want to know about vi are here.
More vi tricks later!!

cat cat filename See contents of a text file. cat


(catenate) will list the whole file
contents. Cat is mostly used to
catenate two or more files to one
file using the redirection
operator.
cat file1 file2 file3 > Catenate the contents of file1,
files file2 and file3 to a single file
called files. If you do not use the
redirection, the result will be
shown on the standard output, i.e.,
screen.
more more Show the contents of the file, one page at a time. In
page filename more/page, use space to see next page and ENTER to
page see next line. If you wish to edit the file (using
filename vi), press v; to quit press q.

tail -n To see the specified number of lines from the end of


tail
filename the file.
head -n To see the specified number of lines from the top
head
filename of the file
env env To see value of all environment variables.
To set an In ksh or sh "export VARIABLENAME=value",
environment Note there is no space between =.
variable: In csh "setenv VARIABLENAME value"
echo See value of an environment variable
$VARIABLENAME

echo echo string To print the string to standard output


echo "Oracle SID Will display "Oracle SID is ORCL" if the
is $ORACLE_SID" value of ORACLE_SID is ORCL.

lp lp filename To print a file to system default printer.

chmod chmod permission Change the permissions on a file - As


filename explained under ls -l, the permissions are
read, write, execute for owner, group and
others.
You can change permissions by using numbers
or the characters r,w,x. Basically, you
arrive at numbers using the binary format.
Examples:
rwx = 111 = 7
rw_ = 110 = 6
r__ = 100 = 4
r_x = 101 = 5
chmod +rwx Give all permissions to everyone on filename
filename
chmod 777
filename
chmod Read, write, execute for owner, read and
u+rwx,g+rx,o-rwx execute for group and no permission for
filename others
chmod 750
filename

chown chown newuser Change owner of a file


filename

chgrp chgrp newgroup Change group of a file


filename
chown Change owner and
newuser:newgroup group of file
filename

compress compress filename Compress a file - compressed


files have extention .Z. To
compress file you need to have
enough space to hold the
temporary file.

uncompress uncompress Uncompress a file


filename

df df [options] Freespace available on the


[moutpoint] system (Disk Free); without
arguments will list all the
mount points.
df -k /ora0 Freespace available on /ora0 in
Kilobytes. On HP-UX, you can
use "bdf /ora0".
df -k . If you're not sure of the mount
point name, go to the directory
where you want to see the
freespace and issue this
command, where "." indicates
current directory.

du du [-s] Disk used; gives operating


[directoryname] system blocks used by each
subdirectory. To convert to KB,
for 512K OS blocks, divide the
number by 2.
du -s gives the summary, no listing
for subdirectories

find Find files. find is a very useful command,


searches recursively through
the directory tree looking for
files that match a logical
expression. It has may options
and is very powerful.
find /ora0/admin Simple use of find - to list
-name "*log" all files whose name end in log
-print under /ora0/admin and its
subdirectories
find . -name to delete files whose name end
"*log" -print in log. If you do not use the
-exec rm {} \; "-print" flag, the file names
will not be listed on the
screen.
grep Global regular expression to search for an expression in a
print file or group of files. grep has
two flavours egrep (extented -
expands wild card characters in the
expression) and frep (fixed-string
- does not expand wild card
characters). This is a very useful
command, especially to use in
scripts.
grep oracle /etc/passwd to display the lines containing
"oracle" from /etc/passwd file.
grep -i -l EMP_TAB *.sql to display only the file names (-l
option) which contains the string
EMP_TAB, ignore case for the string
(-i option), in all files with sql
extention.
grep -v '^#' /etc/oratab display only the lines in
/etc/oratab where the lines do not
(-v option; negation) start with #
character (^ is a special character
indicating beginning of line,
similarly $ is end of line).

ftp ftp [hostname] File Transfer Protocol - to copy


file from one computer to another
ftp AAAd01hp invoke ftp, connect to server
AAAd01hp.
Connected to AAAd01hp.com. program prompts for user name,
220 AAAd01hp.com FTP server enter the login name to AAAd01hp.
(Version 1.1.214.2 Mon May
11 12:21:14 GMT 1998) ready.
Name (AAAd01hp:oracle):BIJU
331 Password required for enter password - will not be
BIJU. echoed.
Password:
230 User BIJU logged in. Specifying to use ASCII mode to
Remote system type is UNIX. transfer files. This is used to
Using binary mode to transfer text files.
transfer files.
ftp> ascii
200 Type set to A. Specifying to use binary mode to
ftp> binary transfer files. This is used for
program and your export dump files.
200 Type set to I. To see the files in the remote
ftp> ls computer.
200 PORT command successful. transfer the file check.sql from
150 Opening ASCII mode data the remote computer to the local
connection for /usr/bin/ls. computer. The file will be copied
total 8 to the present directory with the
-rw-rw-rw- 1 b2t dba 43 Sep same name. You can optionally
22 16:01 afiedt.buf specify a new name and directory
drwxrwxrwx 2 b2t dba 96 Jul location.
9 08:47 app
drwxrwxrwx 2 b2t dba 96 Jul
9 08:49 bin
-rw-rw-rw- 1 b2t dba 187 Jul
30 14:44 check.sql
226 Transfer complete.
ftp> get check.sql
200 PORT command successful. ! runs commands on the local
150 Opening BINARY mode data machine.
connection for check.sql
(187 bytes).
226 Transfer complete.
187 bytes received in 0.02
seconds (7.79 Kbytes/s)
ftp> !ls
AAAP02SN a4m08.txt tom3.txt transfer file from local machine to
a4m01.txt remote machine, under /tmp
ftp> put directory with name test.txt.
a4m01.txt/tmp/test.txt
mail mail "xyz@abc.com" Mail a file to internet/intranet
< message.log address. mail the contents of
message.log file to xyz@abc.com
mail -s "Messages mail the contents of message.log to xyz
from Me" and abc with a subject.
"xyz@abc.com"
"abc@xyz.com" <
message.log

who who [options] to see who is logged in to the computer.


who -T Shows the IP address of each connection

who -r Shows when the computer was last


rebooted, run-level.

ps ps process status - to list the process id,


parent process, status etc. ps without
any arguments will list current sessions
processes.
ps -f ull listing of my processes, with time,
terminal id, parent id, etc.
ps -ef as above for all the processes on the
server.

kill kill [-flag] to kill a process - process id is


processid obtained from the ps command or using
the v$process table in oracle.
kill 12345 Kill the process with id 12345

kill -9 12345 To force termination of process id 12345

script script logfilename to record all your commands and output


to a file. Mostly useful if you want to
log what you did, and sent to customer
support for them to debug. start logging
to the logfilename. The logging is
stopped when you do "exit".

hostname hostname displays the name of the computer.

uname uname -a to see the name of the computer along


with Operating system version and
license info.

date date displays the current date and time.


date "+%m%d%Y" displays date in MM/DD/YYYY format

Das könnte Ihnen auch gefallen