Sunteți pe pagina 1din 54

UNIX - J2EE (LC)

Day 1

Course Objective
To introduce the Unix Operating System To develop an ability to use general Unix commands To develop ability to write programs in shell To develop ability in using Unix utilities To introduce the security issues in Unix

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

This Course does not cover


Differences in command behavior in various Unix flavors Introduction/Implementation of System Calls System Administration in Unix Hacking/Tricky issues in using Unix commands Awk and sed programming

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

References
Brain W. Kernighan and Rob Pike, The UNIX Programming Environment. Stephen Prata, Advanced UNIX - A Programmers Guide. Stephen G. Kochan and Patrick H. Wood, Exploring the Unix System. James R. Groff, Paul N. Weinberg , Understanding Unix - A conceptual guide. Maurice J. Bach, The Design of the Unix Operating System

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Session Plan
Day 1
Introduction to Unix Unix System Architecture Basic Unix Commands Processes in Unix Regular Expressions Introduction to vi editor

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Session Plan
Day 2
Text Processing Commands Process oriented Commands File Handling Commands Types of Shell Shell Programming

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Session Plan
Day 3
Unix Utilities Unix Program Development Tools Unix Communication Security Features

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Introduction to Unix
What is Unix
Unix is a very popular multi-user, multitasking, time-sharing operating system

Need for Unix in todays world


Unix has become the operating system of choice for various engineering and scientific applications

Evolution of Unix
Started in 1965 when AT&T, GE, IBM and Project MAC joined together to develop a time-sharing system named MULTICS (Multiplexed Information and Computing Service)

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Introduction to Unix
Flavors of Unix
AIX (Advanced IBM Unix)
HP-UX ( Hewlett Packard Unix) MINIX (Minimal Unix) SCO UNIX SOLARIS XENIX LINUX, etc

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Features Of Unix
The important characteristic features are
Portability
Unix has been re-written in C , hence it can run on machines from microcomputers to mainframe computers

Security
Without the proper username and passwords, it is not possible to work on Unix

Background Processing
Jobs/Tasks are executed in the background with the minimal interaction from the user

Pipes
Work with multiple commands at the same time
Copyright 2005, Infosys Technologies Ltd # ER/CORP/CRS/OS31/003 Version No: 1.00

Features Of Unix (Contd.)


Redirection Tools
Allow data to be re-directed between files as per the requirement of the user

Software Development Tools


Unix supports any language that has an interpreter or compiler

Stable and Reliable


Less prone to crashes

Communication
Unix has commands which allow communication between different users connected to the system

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Features Of Unix (Contd.)


Easy to write programs
Unix hides machine architecture from the user

Hierarchical File System


Easy to implement and maintain data

Shells
Unix has different types of shells .viz. Bourne, C, Korn, etc

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

System Architecture
Major components of Unix are :
Kernel
Monitors and controls the resources of a computer and allocates them among its users in an optimal manner

Shell
Provides a processing environment for the user programs and acts like a command translator

Utilities
Programs which are used for development purposes

User Applications
Programs written by the user

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

System Architecture

User
SHELL
UNIX

User
SHELL
OTHER APPLICATIONS

COMMANDS
HARDWARE

DATABASE
PACKAGES

KERNEL

COMPILERS
SHELL

SHELL

User

User

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Processing Environment
User Program
Set of instructions written by the user

Process
Instance of a program under execution

Shell
Provides a processing environment for the user programs

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Structure of Unix File System

/ (root)

home bin sh

dev ls tty lp

etc

tmp

lib

usr

passwd shadow

Note: Different variants of UNIX differ slightly in the file system structure. But some of the basic folders are still the same.

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Inodes and Linking A directory


FILENAME INODE NUM FILENAME INODE NUM

Another directory

file1 file2

0221 0412 name1 file3 0221 0981

File1 and name1 are links with same inode numbers


Inode block #0412 #0221
Copyright 2005, Infosys Technologies Ltd # ER/CORP/CRS/OS31/003 Version No: 1.00

Absolute Path and Relative Path


The Absolute Path
The entire pathname starting from root(/) Example
/home/trng10/file1.

The Relative Path


The path relative to your present working directory Example
cd ..

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

How Unix Session Works.


LOGIN SHELL ASKS FOR A COMMAND USER TYPES COMMAND SHELL EXECUTES UTILITY TO CARRY OUT COMMAND USER INTERACTS WITH UTILITY SHELL PROMPTS FOR NEXT COMMAND USER TYPES CONTROL-D LOGOUT
Copyright 2005, Infosys Technologies Ltd # ER/CORP/CRS/OS31/003 Version No: 1.00

Login Sequence.
Login id and password The /etc/passwd file and /etc/shadow file The /etc/profile file Shell prompt

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

System Settings.
The $PATH variable
Shows the location of executables

Aliases
Allows alternate name for commands

The tty, stty commands


Early UNIX had different kind of terminals Today terminals are implemented as software For backward compatibility, tty and stty commands are used

The [ctrl-c] , [ctrl-d] and other keys

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Unix Command Structure


Unix Command line structure
command [options] [arguments]
Microsoft Word Document

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

General Unix Commands


ls - List contents of a directory

ls [option] [filenames]

Microsoft Word ocu nt

cat - Concatenate and display files cat [option...] [file ...]


Microsoft Word ocu nt

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

General Unix Commands


cp - Copy files
cp [option...] [file1] [file2]
Microsoft Word Document

mv - Move or rename files


mv [option...] [file1] [file2]
Microsoft Word Document

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

General Unix Commands


pwd - Display Working directory
pwd
Mi r

cd - Change Working directory


cd [Directory]
Mi r

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

    
t r t

    
t r t

General Unix Commands


mkdir - Make Directories
mkdir [options] DirectoryName
Mi r

rmdir - Remove Directories


Mi r

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

8 765 ()4 3 )2 1)0) (

rmdir [options] DirectoryName

' &%$ # " !  


t r t
t r t

General Unix Commands


rm - Remove files or directories rm [option...] file ...
Micro o t or Docu ent

ln - Make link to files


ln file1 [file2 ...] target
Micro o t or Docu ent

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

C B A @9 C B A @9

General Unix Commands


cal Calendar
cal [options] [arguments]
Microsoft Word Document

who Displays the users connected


who [options]
Microsoft Word Document

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

General Unix Commands


more Allows display page wise more [files]
Micro o t or Docu ent

whoami Display username


Micro o t or Docu ent

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

S R QPI

whoami

H G F ED

Processes in Unix
Process:
Instance of an application in memory
Mi o o o u o n

Process related commands


ps command

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Concept of stdin, stdout and stderr

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Standard Files
Standard Input (0)
This file is opened by shell to accept information.

Standard Output (1)


This file is opened by shell to direct output

Microsoft Word ocu nt

Standard Error (2)


This file is opened by shell for writing error messages

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

VU

Building Block Primitives


Redirection of I/O:
Input to a process can come from either keyboard or a file Output of a process can be sent to either screen or a file

Pipes
Output of one program is piped as input to another program

Microsoft Word Document

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Special Files
/dev/tty
It is used to display on the terminal

/dev/null
This file is used to suppress the output from being displayed Used for suppressing error messages from being displayed on the screen in programs

Mi r s t

Copyright 2005, Infosys Technologies Ltd

e dcb WXa X` YX X W

rd t

ER/CORP/CRS/OS31/003 Version No: 1.00

Regular Expressions
What is it?
String of ordinary and metacharacter which can be used to match more than one type of pattern. Uses character set
* , [], ^, $, {}, etc.

Mi r s t

Copyright 2005, Infosys Technologies Ltd

t srq fgp gi hg g f

rd t

ER/CORP/CRS/OS31/003 Version No: 1.00

The Shell Metacharacters.


* - Matches all filenames in current directory. ? - Matches a single character. [abc] - Matches a single character either a, b or c. [!abc] - Matches a single character which is not a, b or c. [a-c] Matches a single character which is within the range of a and c. ^abc Matches the pattern abc at the beginning of the line. abc$ - Matches the pattern abc at the end of the line.

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Unix.
The Vi Editor.

Editor in Unix
Need for editor in Unix Types of editor
Line Editor
ed : UC Berkeley ex : Powerful than ed, Bell Systems

Full Screen Editor


vi (stands for visual) vim vi improved emacs (GNU)

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

The vi Editor.
The important characteristic features are:
Omnipresent
Works on different Unix flavors

Fast
Various operations are very fast

Powerful UNDO features


Text in lines could be undone with very less effort

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

The vi Editor.
The limitations are:
Less user-friendly
No graphical user interface

Highly Case-sensitive
Letter in small case has a different implementation in comparison with the same letter in upper case

Keystrokes could have more than one meaning


A letter (of the same case) has different implementation across different modes.

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

The vi Editor.
Modes of working:
Command Mode
Keys are interpreted as commands

Insert Mode
Keys are interpreted as data

Escape Mode
Keys are interpreted for saving/exiting purposes

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

vi Operating modes.

i, I , o, O, a, A ..

Command mode :
Enter esc

Insert mode

Escape mode

:q

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Vi editor commands
To move around
h, j, k, l, ^D, ^U, G, 0, ^, $, w, b

Inserting/Deleting text
i, a, I, A, r, R, o, O, dd, dw, c$, D, x, X.

Changing/Replacing text.
cc, cw, c$, ~, J, u, . , yy, yw, p, P

File manipulation.
:w, :wq, ZZ, :w!, :q, :q! , :![command]

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Searching a pattern
/pattern
Searches forward for first occurrence of a pattern.

?pattern
Searches backward for first occurrence of a pattern.

n
Repeats the last search.

N
Repeats the last search command in opposite direction.

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Pattern Substitution.
:s/ptn1/ptn2
Replaces first occurrence of ptn1 with ptn2.

: s/ptn1/ptn2/g
Replaces all occurrences in the current line.

: m, n s/ptn1/ptn2/g
Replaces all occurrences in lines m to n.

: ., $ s/ptn1/ptn2/g
Replaces all occurrences from current line to end of file.

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Customizing vi.
The set command
:set all :set nu

The abbr command


:abbr itl Infosys Technologies Ltd

The map command


:map ^X :wq

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Vi Startup File
.exrc
vi reads .exrc before loading settings are permanent for a vi session

Copyright 2005, Infosys Technologies Ltd

ER/CORP/CRS/OS31/003 Version No: 1.00

Handling multiple files.


vi file1 file2 file3
Opens all files one after another

:n
Permits editing of next file in the buffer

: rew
Permits editing of first file in buffer

: args
Displays names of all files in the buffer

:f
Displays the name of the current file
Copyright 2005, Infosys Technologies Ltd # ER/CORP/CRS/OS31/003 Version No: 1.00

System Variables.
PATH
Search path referred by Unix for any command. echo $PATH

HOME
Indicates the home directory for the user. echo $HOME

Mic oso t o Doc e t

Copyright 2005, Infosys Technologies Ltd

y u u x w v
# ER/CORP/CRS/OS31/003 Version No: 1.00

System Variables (contd).


PS1
Used for displaying & changing the primary prompt. echo $PS1

PS2
Used for changing the secondary prompt.

Mi r s t

Copyright 2005, Infosys Technologies Ltd

rd t

ER/CORP/CRS/OS31/003 Version No: 1.00

set command.
set command
Used for display all the environment variables. Shows the current values of system variables. Also allows conversion of arguments into positional parameters. Syntax : set

Mi r s t

Copyright 2005, Infosys Technologies Ltd

rd t

ER/CORP/CRS/OS31/003 Version No: 1.00

man command.
A screenshot of the man command. Syntax: man <command name>
[ ] indicates optional content

Type the letter q to quit


Copyright 2005, Infosys Technologies Ltd # ER/CORP/CRS/OS31/003 Version No: 1.00

Summary
Background Features of Unix Unix System Architecture Unix File System General Unix commands and utilities Processes Regular Expressions Vi Editor Modes of operation
Copyright 2005, Infosys Technologies Ltd # ER/CORP/CRS/OS31/003 Version No: 1.00

Thank You!
Copyright 2005, Infosys Technologies Ltd # ER/CORP/CRS/OS31/003 Version No: 1.00

S-ar putea să vă placă și