basic unix for db developers
TRANSCRIPT
-
8/8/2019 Basic Unix for DB Developers
1/40
-
8/8/2019 Basic Unix for DB Developers
2/40
Agenda
Introduction - UNIX
General Commands
File System Navigation
File/Directory Manipulation
Data Manipulation
Networking/Communications
Miscellaneous
vi Editor
sed and awk command
-
8/8/2019 Basic Unix for DB Developers
3/40
Introduction
Unix Evolution
1969 -- Bell Telephone Laboratories : A joint attempt by BTL, GE, andMIT to create an OS for a large computer which can accommodate upto a thousand simultaneous users.
Ken Thompson and Dennis Ritchie worked on Multicast (MultiplexedInformation and Computing Service)
BTL withdrew from the project and OS was rewritten on anothersmaller machine (a DEC PDP-7 [Programmed Data Processor] with
4K memory for user programs). The result was a system called UNICS (UNiplexed Information and
Computing Service)
UNICS was renamed as UNIX .
-
8/8/2019 Basic Unix for DB Developers
4/40
Popular versions of UNIX
SCO UNIX SCO Open Desktop and SCO Open Server from the
Santa Cruz Operation for the Intel platform. Basedon System V.
SunOS Suns early OS and the best-known BSD operatingsystem.
Solaris Suns SRV4 implementation, also referred to as
SunOS 5.x.HP-UX Hewlett-Packards version of UNIX.HP-UX 9.x was
System V, release 3, and HP-UX 10 is based on theSystem V, release 4 OS.
Digital UNIX Digital Equipments version of OSF/1.
IRIX The Silicon Graphics version of UNIX. Early versionswere BSD-based; version 6 is System V, release 4.
AIX IBMs System V-based UNIX.
Linux A free UNIX operating system for the INTELplatform.
-
8/8/2019 Basic Unix for DB Developers
5/40
Introduction To Unix OS
The UNIX OS was designed :
By programmers for programmers.
To let a number of programmers access the computer at
the same time and share its resources. To control all of the commands from all of the keyboards
and all of the data being generated.
To permit each user to believe he or she is the only personworking on the computer.
This real-time sharing of resources make UNIX one of themost powerful operating systems ever.
-
8/8/2019 Basic Unix for DB Developers
6/40
Features Of UNIX
Multitasking capability
Multi-user capability
Portability
UNIX tools : Integral
Non -Integral
UNIX Communications
Applications libraries
-
8/8/2019 Basic Unix for DB Developers
7/40
UNIX Organization
Kernel : schedules tasks and manages storage;Shell : connects and interprets users' commands, calls programs frommemory, and executes them .Tools and applications : offer additional functionality to OS.
-
8/8/2019 Basic Unix for DB Developers
8/40
General
exit : Terminate your current session, or shell.
man command : Display the Unix manual page
describing a given Unix command.
login : Type the userid,
press ENTER and supply the password
To logout : exit
To change the password :
$passwd [ENTER]
-
8/8/2019 Basic Unix for DB Developers
9/40
General
pwd : writes an absolute path name of thecurrent working directory to standard output.
cd, chdir : change working directory
-
8/8/2019 Basic Unix for DB Developers
10/40
The who Utility
The who utility can list :
the user's name
terminal line
login time elapsed time since activity occurred on the line
the process-ID of the command interpreter (shell).
File /var/adm/wtmp, contains a history of all the logins
The general format for output is:
name [state] line time [idle] [pid] [comment] [exit]
-
8/8/2019 Basic Unix for DB Developers
11/40
File System Navigation
cd : Return to your home directory. cd directory: Change directory to make directory your current
directory.
file files : Determine file type.
ls : List the contents of the current directory.
ls names : List the contents of the directories; names canname files and/or directories:
ls -l : . . . in a long format, showing permissions, owner,size, and other file info.
ls -a : . . . all files, including "hidden" files (file names that
begin with a dot "."). ls R : . . . Recursively, for all subdirectories.
ls -t : . . . in time order (when modified, newest to oldest)rather than in name order.
pwd : Display the name of the current directory, or "print
working directory."
-
8/8/2019 Basic Unix for DB Developers
12/40
File/Directory Manipulation
compress files : Reduces the size of a file.
uncompress files : Restores compressed files to their original form. cp file1 file2: Copy file(s).
cp files directory: Copy file(s) into a directory.
cp -rdir1 dir2 : Copy a directory and, recursively, itssubdirectories.
mkdirdirectory: Create, or "make" a directory.
mv file1 file2: Move a file or, if file1 and file2 are in the samedirectory, rename a file.
mv files directory: Move files into a directory.
mv dir1 dir2: If directory dir2 exists, move dir1 into dir2; otherwise,rename dir1 as dir2.
rm files : Remove (erase) file(s).
rm -rnames : Remove files, directories, and recursively, anysubdirectories.
rmdirdirectory: Remove directory (directory must be empty).
-
8/8/2019 Basic Unix for DB Developers
13/40
Data Manipulation
cat files : Concatenate file(s); you can use cat to display the
contents of a file (this is not advisable if the file is a binary file).
grep "pattern" files : Display all lines in the files that match a pattern.
more files : Display contents of files one screen at a time.
sort files : Order the lines in a file or files alphabetically (thiscommand does not alter the file or files -- it merely displays thesorted output to the screen):
sort -rfiles : . . . in reverse order.
-
8/8/2019 Basic Unix for DB Developers
14/40
Networking/Communications
ssh hostname : Connect to a remote host using Secure Shell.
telnet hostname : Connect to a remote host using the telnetprotocol.
talk user : Initiate a conversation with another user (endconversation with Control-C); talk works only between machines of
the same architecture ftp : The command file transfer protocol attaches you to another IP
device
e.g.
ftp 141.205.15.154 ( Attaches you to the device with
address 141.205.15.154. You are normallypresented witha loginandpassword screen )
-
8/8/2019 Basic Unix for DB Developers
15/40
Networking/Communications
Commands that are used in FTP are:
dir- directory listing. quit - quit from ftp. cd - change directory. get ormget - get a file (or multiple files).
put ormput - put a file (or multiple files). bin - sets up your system to receive binary files. hash - displays hashes whilst files are being transferred. lcd - local change directory changes the directory on your local
machine to which you are sending and receiving files. This is usefulas it saves you having to quit ftp to carry out the directory change.
The Hosts file can be found in the directory '/etc'.
-
8/8/2019 Basic Unix for DB Developers
16/40
Networking/Communications
netstat : This stands fornetwork statistics,e.g.
netstat -r displays the routing table of the Unix box.netstat -a displays all network information.
ping : Ping an IP devicee.g.
ping 141.205.51.26
rlogin : This works like telnet,e.g.
rlogin 141.205.52.16 takes you to another Unix machineonly. To quit you press 'return', '~', .' and 'return' again.
Ifconfig : This displays the IP configuration of the box, e.g.e.g.
ifconfig -a displays all IP configuration.
-
8/8/2019 Basic Unix for DB Developers
17/40
Networking/Communications
snoop : This command captures the network packets ina readable formate.g.
snoop -p 23 ( Captures all IP traffic using port 23(Telnet). use Ctrl-C to stop the snoop.)
vstat : This displays CPU utilization and gives a list ofprocesses and their share of CPU utilization,
e.g.vstat 10 ( displays the CPU utilization every 10
seconds.)
-
8/8/2019 Basic Unix for DB Developers
18/40
Miscellaneous
!! : Repeat last shell command.
!string : Repeat last shell command that began with string (for example, type"!m" to repeat the last command that began with "m").
cal : Display a calendar of the current month.
cal month year : Display a calendar of the given month and year. Note thatthe year must be fully qualified, for example, "2003" and not "03."
clear : Clears terminal screen.
date : Display the current local date and time.
Difference between who am i, whoami:
who am i : tells me who I am. prompt who am i
On the other hand,
whoami : displays the effective current username.
-
8/8/2019 Basic Unix for DB Developers
19/40
df
Displays number of free disk blocks and files .
-a Report on all file systems
-b Print the total number of kilobytes free.
-e Print only the number of files free.
-F FSType Specify the FSType on which to operate.
The -F option is intended for use with unmounted filesystems.
-l Report on local file systems only.
-n Print only the FSType name.
-o FSType-specific_options -t Print full listings with totals.
-V Echo the complete set of file system specific commandlines
-
8/8/2019 Basic Unix for DB Developers
20/40
du
Reports on number of 512 bytes blocks ofevery directory in the system.
-
8/8/2019 Basic Unix for DB Developers
21/40
recursively descends the directory hierarchy for each
path seeking files that match a Boolean expressionwritten in the primaries given below.
SYNOPSIS
find path... Expression
Example :$find / -name passwd print
$find user singh print
$find name -print
The Find Utility
-
8/8/2019 Basic Unix for DB Developers
22/40
cat
The cat utility reads each
file in sequence andwrites it on thestandard output
SYNOPSIS
examplecat file
cat file1 file2 >file3
-n Precede each line output
with its line number.
-b as -n, but omit the linenumbers from blank lines.
-u The output is not buffered.
-s silent about non-existentfiles.
-v Non-printing characters areprinted visibly
cat [-nbsuvet] [file]...
-
8/8/2019 Basic Unix for DB Developers
23/40
File access
$ cat > homefiles
echo "files in the home directory \n
cd;pwd
ls -l |more
$ chmod +x homefiles
-
8/8/2019 Basic Unix for DB Developers
24/40
chmod
chmod changes or assigns the mode of a file. Themode of a file specifies its permissions and otherattributes.
The mode may be absolute or symbolic.
u user
g group
o other
+ add permission
- remove permission
= Enable setting
r=4 read permission
w=2 write permission
x=1 execute permission
-
8/8/2019 Basic Unix for DB Developers
25/40
Examples : chmod
Deny execute permission to everyone: chmod a-x fileAllow only read permission to everyone: chmod 444file
Make a file readable and writable by the group and
others:chmod go+rw file
chmod 066 file
Allow everyone to read, write, and execute the file and
turn on the set group-ID.chmod a=rwx,g+s file
chmod 2777 file
-
8/8/2019 Basic Unix for DB Developers
26/40
grep utility
The grep utility searches text files for a pattern and printsall lines that contain that -pattern
grep [-bchilnsvw] limited-regular-expression [filename]
-
8/8/2019 Basic Unix for DB Developers
27/40
wc utility
The wc utility reads one or more input files and, by default,
writes the number of newline characters, words and bytescontained in each input file to the standard output.
wc [ -c| -m| -C] [-lw] [file]
-c Count bytes.
-m and -C Count characters.
-l Count lines.
-w Count words delimited by white space
characters or new line characters.Example :
#wc -clw xxx.txt
-
8/8/2019 Basic Unix for DB Developers
28/40
More : Browse or page through a text file .
page : page through a text file .
Examples :
more /etc/passwd
more /etc/inittab
More, Page
-
8/8/2019 Basic Unix for DB Developers
29/40
head & tail
The head / tail utility copies the first/last number of linesof each filename to the standard output.
The default value of number is 10 lines.
Example :$Head -10 phone.txt
$tail +5 phone.txt
-
8/8/2019 Basic Unix for DB Developers
30/40
cmp ,diff ,EOF, BOF
cmp utility compares two files and reports the firstdifference that id fineds.
diff utility echoes the different lines.
Examples :
diff phone.txt phone.old
diff phone.txt phone.old
-
8/8/2019 Basic Unix for DB Developers
31/40
Printing files
1. Using cat & cp commands (if printer is connected toterminal port 8):
cat phone.txt > /dev/tty8cp /etc/inittab /dev/tty8
2. If printer is directly connected to the serial printer port onthe CPUcat phone.txt >/dev/ptrs
3. To know the status of the printer : lpstat t
4. Adding files to print-job queue :lp chap1 chap2 chap3
-
8/8/2019 Basic Unix for DB Developers
32/40
ps utility
ps (process status) : for viewing the status of allthe unfinished jobs that have been submitted tothe kernel.
Example:
ps -ef
ps -ef | grep yourusername
-e option : include all processes (including others)-f option : give a long listing.
-
8/8/2019 Basic Unix for DB Developers
33/40
Killing processes
Use kill utility to terminate processes.
Some processes refuse to die easily, use the "-9"option to force termination of the job.
EXAMPLE: force termination of a job whose process IDis 111
kill -9 111
-
8/8/2019 Basic Unix for DB Developers
34/40
The "tar" command stands fortape archive.
This command is used to create new archives, listfiles in existing archives, and extract files fromarchives.
tar
-
8/8/2019 Basic Unix for DB Developers
35/40
Vi Editor
The VI editor is a screen-based editor used by many Unix users. The VI editoruses the full screen, so it needs to know what kind of terminal you have. Whenyou log in, wiliki should ask you what terminal you have. The prompt looks likethis: TERM = (vt100)
For C shell (/bin/csh), the command is this:set term=vt100
For Bourne Shell (/bin/sh) or Korn Shell (/bin/ksh), the commands are the
following:export TERM
TERM=vt100
Next, reset your terminal with this command:tset
Starting the vi Editor
The vi editor lets a user create new files or edit existing files. The command tostart the vi editor is vi, followed by the filename.
-
8/8/2019 Basic Unix for DB Developers
36/40
Vi Editor
vi or < no filename >( it will ask filenamewhile saving the file.)
Useful vi commands
i : insert mode.
: leave insert mode and go into commandmode.
a : append characters to the end of the line.
o : open a line below your cursor.
O : open a line above. g : go to the bottom of the file.
r : replace the letter that you are on with the one you
type next.
-
8/8/2019 Basic Unix for DB Developers
37/40
Vi Editor
x erase the character that you are on. dd delete the line that you are on. A number before dd deletes that
number of lines. yy copy the line you are on. A number before yy copies that number of
lines. p paste the line you are on below you.
P paste the line you are on above you. :wq write and quit the file that you are editing. :wq! write and quit the file that you are editing, even if it is designated as
read only! :w! write to a read only file. :q quit. :q! discard any editing and quit.
/ this takes you to the bottom of the window where you can type a stringand return to perform a search in the file.
Note : (The character! is often referred to as pling )
-
8/8/2019 Basic Unix for DB Developers
38/40
sed Command
A stream editor.
Syntax
sed [ -n ] Script[ File ... ]sed [ -n ] [ -e Script] ... [ -fScriptFile ] ... [ File ... ]
Description
The sed command modifies lines from the specified File parameteraccording to an edit script and writes them to standard output. The sedcommand includes many features for selecting lines to be modified andmaking changes only to the selected lines.
The sed command uses two work spaces for holding the line being
modified: the pattern space, where the selected line is held; and the holdspace, where a line can be stored temporarily.
-
8/8/2019 Basic Unix for DB Developers
39/40
awk Command
Finds lines in files that match patterns and then performs specified actions on them.
Syntax
awk [ -F Ere ] [ -v Assignment ] ... { -fProgramFile | 'Program' } [ [ File ... | Assignment ... ] ] ...
Description
The awk command utilizes a set of user-supplied instructions to compare a set of files, one line
at a time, to extended regular expressions supplied by the user. Then actions are performedupon any line that matches the extended regular expressions. The maximum record size thatawk processes is 10KB.
The pattern searching of the awk command is more general than that of the grep command, andit allows the user to perform multiple actions on input text lines. The awk commandprogramming language requires no compiling, and allows the user to use variables, numeric
functions, string functions, and logical operators.
The awk command is affected by the LANG, LC_ALL, LC_COLLATE, LC_CTYPE,LC_MESSAGES, LC_NUMERIC, NLSPATH, and PATH environment variables.
-
8/8/2019 Basic Unix for DB Developers
40/40
Thank You