UNIX Architecture UNIX Command The vi editor UNIX Shell Scripting
Introduction:
Unix is a multitasking, multi-user computer operating sstem!
Unix "as originall developed in #$%$ & a group o' AT(T emploees!
Solaris Unix, AIX, )* Unix and +S are 'e" avors o' UNIX!
UNIX Architecture
S/00 NI*UNA S12T3A/0 S14UTI1NS
.
UNIX Architectur Architecture e UNIX Architecture consists o' t"o parts: •
•
Shell 5ernal
Shell: A Unix shell is a command-line interpreter! Kernal: A Unix kernel is a computer program that manages input6output input6ou tput re7uests 'rom so't"are and translates into data processing processing
them
instructions 'or the central processing processing
unit and other electronic components o' a computer!
ls command list all the 9les and directories availa&le in current director director!!
S/00 NI*UNA S12T3A/0 S14UTI1NS
;
ls -l •
4ist all 9les and directories 'rom current director in long 'ormat!
S/00 NI*UNA S12T3A/0 S14UTI1NS
$
ls -a •
ispla all 9les including hidden 9les!
S/00 NI*UNA S12T3A/0 S14UTI1NS
#<
ls -la •
Using multiple options at a time!
S/00 NI*UNA S12T3A/0 S14UTI1NS
##
touch Sntax: •
touch <!lena"e
touch command creates =ero &te 9les!
S/00 NI*UNA S12T3A/0 S14UTI1NS
#>
cat Sntax: cat •
<!lena"e
cat command displas the content o' a 9le!
S/00 NI*UNA S12T3A/0 S14UTI1NS
#?
cat Sntax: cat •
<!lena"e# <!lena"e$
cat command displas the content o' a 9le!
S/00 NI*UNA S12T3A/0 S14UTI1NS
#.
cat Sntax: cat • •
•
• • •
<!lena"e
Creates a 9le "ith ne" 9le name n ame and open 'or editing! Use ctrl@d kes to exit edit mode 1pens an existing 9le in overriding overriding mode! Sntax:
cat <!lena"e
Creates a 9le "ith ne" 9le name n ame and open 'or editing! Use ctrl@d kes to exit edit mode 1pens an existing 9le in appending mode!
S/00 NI*UNA S12T3A/0 S14UTI1NS
#8
cp Sntax: •
cp <!lena"e <ne% !lena"e
cp command cop data 'rom one 9le to other!
S/00 NI*UNA S12T3A/0 S14UTI1NS
#%
mv Sntax: "& •
•
<!lena"e <ne% !lena"e
mv command move data 'rom one 9le to other, old 9le exits! /ename a old 9le to ne" 9le!
S/00 NI*UNA S12T3A/0 S14UTI1NS
#
S14UTI1NS
rm • •
Sntax: r" <option <!lena"e rm command comman d remove 9 9les les 'rom ' rom current director! director! /m command cant remove directories!
S/00 NI*UNA S12T3A/0
#
S14UTI1NS
#;
"c •
Sntax: %c
<option "c command displas <!lena"e num&er o' ne" lines, "ords and Num&er o' &tes 'rom 9le!
S/00 NI*UNA S12T3A/0
Cont!!
S14UTI1NS
#$
"c
S/00 NI*UNA S12T3A/0
Cont!!
S14UTI1NS
"c
S/00 NI*UNA S12T3A/0
><
S14UTI1NS
"c Bl 9lenameD
S/00 NI*UNA S12T3A/0
>#
S14UTI1NS
>>
sort •
Sntax: sort <!lena"e Sort command "ill sort the data in 9le &ased on 9rst column!
S/00 NI*UNA S12T3A/0
Cont!!
S14UTI1NS
>?
uni7 uni' <!lena"e uni7 command remove the duplicates that are se7uent present present in a 9le! Sntax:
•
S/00 NI*UNA S12T3A/0
Cont!!
S14UTI1NS
>.
uni7
S/00 NI*UNA S12T3A/0
Cont!!
S14UTI1NS
>8
uni7
S/00 NI*UNA S12T3A/0
Cont!!
S14UTI1NS
p"d Sntax: p%( •
p"d command c ommand displa current director! director!
S/00 NI*UNA S12T3A/0
>%
S14UTI1NS
>
chmod chmod command changes the permissions o' a 9le! •
1rder o' permissions in Unix: O%ner per"issions: Actions the o"ner o' the 9le can per'orm on the 9le! )roup per"issions: A mem&er o' the group that a 9le &elongs to, can per on the 9le! Other per"issions: 3hat action all other users can per'orm on the 9le! *ermission Ealues: # - 0xecute > - 3rite . - /ead
S/00 NI*UNA S12T3A/0
S14UTI1NS
chmod Sntax:
ch"o( <per"issions <!lena"e
S/00 NI*UNA S12T3A/0
>;
S14UTI1NS
cut Sntax: cut <option <!lena"e •
cut command to extract portion o' text 'rom a 9le & selecting columns!
S/00 NI*UNA S12T3A/0
>$
S14UTI1NS
grep Sntax: *rep <pattern <!le na"e
grep command search 'or a pattern in a 9le and print! •
S/00 NI*UNA S12T3A/0
?<
S14UTI1NS
head Sntax: hea( <option <!le na"e •
head command displas top #< lines o' 9le!
S/00 NI*UNA S12T3A/0
?#
S14UTI1NS
?>
tail Sntax: tail <option <!le na"e •
tail command displas &ottom #< lines o' 9le!
S/00 NI*UNA S12T3A/0
S14UTI1NS
??
head ( tail Sntax:
hea( <option <!le na"e+tail <option
S/00 NI*UNA S12T3A/0
S14UTI1NS
mkdir Sntax: •
",(ir <(irector- na"e
mkdir command is used to create directories! directories!
S/00 NI*UNA S12T3A/0
?.
S14UTI1NS
rmdir Sntax: •
r"(ir <(irector- na"e
rmdir command is used to remove directories!
S/00 NI*UNA S12T3A/0
?8
S14UTI1NS
?%
cd Sntax: •
c( <(irector- na"e
cd command is used to move to other directories! directories!
S/00 NI*UNA S12T3A/0
S/00 NI*UNA S12T3A/0 S14UTI1NS
du Sntax: •
(u
du command gives disk usage details!
?
S/00 NI*UNA S12T3A/0 S14UTI1NS
du -h Sntax:
(u .h
du Bh command gives disk usage details in human understanda&le 'ormat! •
?;
S/00 NI*UNA S12T3A/0 S14UTI1NS
d' Sntax: •
(/
d' command gives space availa&ilit on disk!
?$
S/00 NI*UNA S12T3A/0 S14UTI1NS
.<
d' -h Sntax:
(/ .h
d' -h command gives space availa&ilit on disk in human understanda&le language! •
S/00 NI*UNA S12T3A/0 S14UTI1NS
ps Sntax:
ps
ps command gives all a ll processes details that are currentl runni running! ng! •
.#
S/00 NI*UNA S12T3A/0 S14UTI1NS
.>
ps -e' Sntax:
ps .e/
ps Be' command gives all processes details that ar currentl currentl running along "ith user name! •
S/00 NI*UNA S12T3A/0 S14UTI1NS
.?
kill Sntax: •
,ill <option <process i(
kill command kills the process running "ith given i
S/00 NI*UNA S12T3A/0 S14UTI1NS
date Sntax: •
(ate
date command displas current current date!
..
S/00 NI*UNA S12T3A/0 S14UTI1NS
.8
sed Sntax:
se( <operation !lena"e
sed stands 'or stream editor! sed command is used to modi' data in 9les automaticall automa ticall!! •
S/00 NI*UNA S12T3A/0 S14UTI1NS
sed Sntax:
se( <operation !lena"e
.%
S/00 NI*UNA S12T3A/0 S14UTI1NS
.
sed Sntax: •
•
se( <operation !lena"e
se( 0s1In/or"atica1In/or"atica2 0s1In/or"atica1In/or"atica21$0 1$0 !le3t4t Replaces the secon( occurrence o/ the %or(3 se( 0s1In/or"atica1In/or"atica2 0s1In/or"atica1In/or"atica21*0 1*0 !le3t4t
Replace all the occurrence o/ the pattern in a l
S/00 NI*UNA S12T3A/0 S14UTI1NS
.;
nohup Sntax: •
nohup <options 5
nohup stands 'or no hang up! nohup is used to run the process even a'ter logout 'rom a shell!
•
F nohup sh custom-script!sh (
•
F nohup sh custom-script!sh D custom-out!log (
S/00 NI*UNA S12T3A/0 S14UTI1NS
.$
"ho am i Sntax: •
%ho a" i
"ho am I gives the details o' current user "ho is logged into the UNIX machine!
S/00 NI*UNA S12T3A/0 S14UTI1NS
8<
man
"an command nameD man command displas the manual 'or given comman
Sntax: •
S/00 NI*UNA S12T3A/0 S14UTI1NS
8#
9nd !n( <location to search <t-pe to search <& 9nd command displas the location o' given 9le!
Sntax:
S/00 NI*UNA S12T3A/0 S14UTI1NS
The vi editor editor •
•
Stands 'or 6isual E(itor! Godes o' operation - Command mode - Insert mode - The ex command mode
8>
S/00 NI*UNA S12T3 S12T3A/0 A/0 S14UTI1NS
The vi editor editor
8?
S/00 NI*UNA S12T3A/0 S14UTI1NS
The vi editor editor
8.
S/00 NI*UNA S12T3A/0 S14UTI1NS
The vi editor editor
88
S/00 NI*UNA S12T3A/0 S14UTI1NS
editor - commands The vi editor HH B "rite &uer to 9le and 7uit :"7 - "rite &uer to 9le and 7uit :7J B Kuit the editor "ithout saving changes to the 9le! :7 B Kuit i' the changes "ritten to 9le!
8%
S/00 NI*UNA S12T3A/0 S14UTI1NS
Sample script t n e m m c o
2ollo"ing commands Needs to &e executed
8
S/00 NI*UNA S12T3A/0 S14UTI1NS
1utput
8;
S/00 NI*UNA S12T3A/0 S14UTI1NS
Name!sh
1utput:
8$
S/00 NI*UNA S12T3A/0 S14UTI1NS
e9ning varia&les Earia&le nameLvaria&le value
%<
S/00 NI*UNA S12T3A/0 S14UTI1NS
%#
Special varia&les 78 . !lena"e o/ the current cu rrent script3
7n& . Ar*u"ents %ith %hich a script %as in&o,e(397#7$ in&o,e(397#7$ an( so on 7 . Nu"=er o/ ar*u"ents supplie( to a script 7> . All the ar*u"ents are (ou=le 'uote(3 7? . All the ar*u"ents are in(i&i(uall- (ou=le 'uote(3 7@ . E4it status o/ the last co""an( 77 . Process nu"=er o/ the current shell 7 . Process nu"=er o/ the last =ac,*roun( co""an(
S/00 NI*UNA S12T3A/0 S14UTI1NS
/elational operators -e7 - 07ual to -ne - Not e7ual to -gt - Mreater than -lt - less than -ge - Mreater than or e7ual to -le - 4ess than or e7ual to
%>
S/00 NI*UNA S12T3A/0 S14UTI1NS
I'!else i'conditionD statementD 9 i'condition D statement D 0lse statement D 9
I'conditionD statementD eli'condition D statementD 0lse
%?
statementD 9
S/00 NI*UNA S12T3A/0 S14UTI1NS
I'!else OJ6&in6sh aL#< &L>< i' P Fa LL F& Q then echo Ra is e7ual to &R 9 i' P Fa JL F& Q then echo Ra is not e7ual
%.
to &R 9
Sntaxes Some Sntax es •
case!!!esac
"hile command# do Statements •
"hile command> do Statements done Statements done