Anda di halaman 1dari 95

11/29/2010

Omega
Training & Consultancy

OMG-150
UNIX
FUNDAMENTALS
BinnurKurt,Ph.D.
OmegaTrainingandConsultancy
www.omegaegitim.com

binnur.kurt@omegaegitim.com

UNIX Fundamentals

Omega

Training & Consultancy

CourseOverview
1. Solaris10OperatingSystem
2. CommandLineFeatures
3. ViewingDirectoriesandFiles
4. WorkingwithDirectoriesandFiles
5. Thevi Editor
6. UsingCommandsWithintheShell
7. BasicFilePermissions
8. AccessControlLists
9. SearchingFilesandDirectories
10. BasicProcessControl

11/29/2010

Omega

UNIX Fundamentals

Training & Consultancy

ImportantCourseInformation
> Duration
1Day
> CourseHours
9:3012:30
13:3016:30

Omega

UNIX Fundamentals

Training & Consultancy

Background
1995,B.Sc.,ITU ComputerEngineering
1997,M.Sc.,ITU ComputerEngineering
2007,Ph.D.,ITU ComputerEngineering
19952003,RA, ITUCE
20042008,Lecturer, ITUCE
2008todate,Trainer,OmegaTraining&Consultancy
2008todate,VisitingFacultyMember,ITU CE
Biliim Teknolojileri TYLProgram
2004todate,AhmetYeseviniversitesi,UzaktanEitim,
InternetWebServisleri

11/29/2010

UNIX Fundamentals

Omega

Training & Consultancy

Contact
binnur.kurt@gmail.com
http://www2.itu.edu.tr/~bkurt
http://www.omegaegitim.com

UNIX Fundamentals

Omega

Training & Consultancy

AreasofInterest
>
>
>
>
>
>
>
>

JavaDesktopandEnterpriseTechnologies
CompositeApplicationDevelopment
SoftwareEngineering
OOAnalysisandDesign
MySQL,Oracle
SunJavaDirectoryServer,ApplicationServer
DigitalImage&VideoAnalysisandProcessing
RealTimeComputerVisionSystems

11/29/2010

Omega

UNIX Fundamentals

Training & Consultancy

TrainingsOffered
OS

Programming

C/C++
Fortran 2003

Database

AS
WebLogic Server

UNIX Fundamentals

Omega

Training & Consultancy

TrainingsOffered
JavaEE
Frameworks

11/29/2010

UNIX Fundamentals

Omega

Training & Consultancy

MyCertifications

UNIX Fundamentals

Omega

Training & Consultancy

MyRecentBooks

B.Kurt,Z.ataltepe,PlatformsforEnterpriseServers,pp.209
223,Chapter9,CRCPress,2010.

11/29/2010

UNIX Fundamentals

Omega

Training & Consultancy

MyRecentBooks
F.Kahraman,B.Kurt,M.Gkmen,RobustFaceAlignmentforIlluminationandPose
InvariantFaceRecognition,InTech,April2010.

Omega
Training & Consultancy

Module 1
UNIX
Operating System

11/29/2010

UNIX Fundamentals

UNIX Operating System

WhatisanOperatingSystem?
> Anelephantisamousewithanoperatingsystem.

13

UNIX Fundamentals

UNIX Operating System

WhatisanOperatingSystem?
> Apieceofsoftwarethatprovidesaconvenient,
efficientenvironmentfortheexecutionofuser
programs.
Users
Applications software
Kernel
Operating systems
Hardware
14

11/29/2010

UNIX Fundamentals

UNIX Operating System

ResourceAbstractionandSharing
> Hidesthedetailsofhowthehardwareoperates
> Providesanabstractmodeloftheoperationof
hardwarecomponents
generalizehardwarebehavior
limittheflexibilityinwhichhardwarecanbe
manipulated
> Computationmodel:processes,threads
> Resources:memory,disk,files,cpu,etc.
15

UNIX Fundamentals

UNIX Operating System

UNIX

16

11/29/2010

UNIX Fundamentals

UNIX Operating System

Kernel
> ThekernelisthecoreoftheOS
> Managesallthephysicalresourcesofthecomputer
> Aftertheshellpassesthecommands,thekernel
executesthecommands.

17

UNIX Fundamentals

UNIX Operating System

Shell
Theshellperformsthefollowing:
> Actsasaninterfacebetweentheuserandthekernel
> Actsasacommandlineinterpreter
> Takesthecommandsthatauserenters
> Processesthecommandlineenteredbyauser
> Passestheinterpretedcommandlinetothekernel

18

11/29/2010

UNIX Fundamentals

UNIX Operating System

Shell
>
>
>
>
>

BourneShell
Korn Shell
CShell
TCShell
B(ourne)A(gain)sh Shell

sh
ksh
csh
tcsh
bash

19

UNIX Fundamentals

UNIX Operating System

DirectoryHierarchy
> Thedirectoryhierarchycontainsan
organizedgroupofdirectoriesand
files.

20

10

11/29/2010

Omega
Training & Consultancy

Module 2
Command-Line
Features

UNIX Fundamentals

Command-Line Features

IntroducingCommandLineSyntax
> Youcanchangethebehaviorofcommandfunctions
byusing optionsandarguments,asshowninthe
followingtable:

> Youcanrunacommandwithoutoptionsand
arguments.
> Youcanruncommandswithoptions,witharguments,
orwithbothoptionsandarguments.
22

11

11/29/2010

UNIX Fundamentals

Command-Line Features 2

IntroducingCommandLineSyntax
>
>
>
>
>
>
>
>
>

$uname
$uname a
$uname i
$uname r
$uname s
$uname rs
$uname sr
$uname rs
$uname sr
23

UNIX Fundamentals

Command-Line Features

IntroducingCommandLineSyntax
> $uname rsi
> $uname rs i
> $uname rsi

24

12

11/29/2010

UNIX Fundamentals

Command-Line Features 2

IntroducingCommandLineSyntax
> $cal
> $cal71973

25

UNIX Fundamentals

Command-Line Features

IntroducingCommandLineSyntax
> $ls
> $ls l
> $ls l dante

26

13

11/29/2010

UNIX Fundamentals

Command-Line Features 2

IntroducingCommandLineSyntax
> $sleep10
> $sleep10^C

27

UNIX Fundamentals

Command-Line Features

ControlCharacters

28

14

11/29/2010

Command-Line Features 2

UNIX Fundamentals

EnteringMultipleCommands
onaSingle CommandLine
> Youcanentermultiplecommandsonasingle
commandline byusingasemicolon(;)toseparate
eachcommand.
> Theshellrecognizesthesemicolonasacommand
separator
$cal71973;date;uname rs
$(cal71973;date);uname rs
runsinasubshell
29

UNIX Fundamentals

Command-Line Features

DisplayingtheOnlineManualPages
> TheonlineUNIXReferenceManual(man)pages
provide detaileddescriptionsofUNIXcommandsand
howtouse them.
> Usetheman commandtodisplaythemanpageentry
that explainsagivencommand.

30

15

11/29/2010

UNIX Fundamentals

Command-Line Features 2

ScrollinginManPages
> Thistableshowsthekeysonthekeyboardthatyou
useto controlthescrollingcapabilitieswhenyouare
intheman pages.

31

UNIX Fundamentals

Command-Line Features

SearchingtheManPages
> Therearetwowaystosearchforinformationinthe
manpages:
Youcansearchamanpagebysection
Youcansearchamanpagebyakeyword

$manlpasswd
$manpasswd
$mans4passwd
$mankcalendar
32

16

11/29/2010

UNIX Fundamentals

Command-Line Features 2

UsingOnlineProductDocumentation
> TostartaWebbrowserinthedesktopenvironment:
ClickLaunch>FirefoxWebBrowser
ClickLaunch>Applications>Internet>FirefoxWeb
Browser.
> ToaccesscomprehensiveinformationonSun
products,visittheWebsitehttp://docs.sun.com
usingyourWebbrowser.

33

UNIX Fundamentals

Command-Line Features

Thedocs.sun.com WebSite

34

17

11/29/2010

Omega
Training & Consultancy

Module 3

Viewing
Directories
and Files

UNIX Fundamentals

Viewing Directories & Files 3

DeterminingtheCurrentDirectory
> Thepwd commandidentifiesthedirectorythatyou
arecurrentlyaccessing.
> $pwd

36

18

11/29/2010

UNIX Fundamentals

Viewing Directories & Files 3

DisplayingtheDirectoryContents
> Youcanviewahierarchyofthefilesanddirectoriesin
the /export/home/user1directoryusingthels
command.

37

UNIX Fundamentals

Viewing Directories & Files 3

DisplayingtheDirectoryContents
> Displayinghiddenfiles
> Displayingalonglist
Youcanusethels -l commandtoview
detailedinformationaboutthecontentsofa
directory.
Theoutputofthels -l commandshowsalong
listingoffileinformation.

38

19

11/29/2010

UNIX Fundamentals

Viewing Directories & Files 3

Whatisahiddenfile?
$ touch apple
$ ls
$ touch .pear
$ ls
$ ls a

(whatdoyousee?
doyouseeapple?)
(doyousee.pear?)
(whataboutnow?)

39

UNIX Fundamentals

Viewing Directories & Files 3

DisplayingtheDirectoryContents

40

20

11/29/2010

UNIX Fundamentals

Viewing Directories & Files 3

DisplayingtheDirectoryContents
> Toviewdetailedinformationonthecontentsofthe
dir1 directory,performthels -l dir1 command
fromtheuser1 directory.

41

UNIX Fundamentals

Viewing Directories & Files 3

DisplayingtheDirectoryContents
> Displayingindividualdirectories
ls ld /etc
> Displayingarecursivelist
ls R /etc
ls R /

42

21

11/29/2010

UNIX Fundamentals

Viewing Directories & Files 3

DisplayingFileTypes
> Youcanuseeitherthels F commandorthe
file command todisplayfiletypes.
> Thistableshowsthesymbolsusedwiththels -F
command output:

43

UNIX Fundamentals

Viewing Directories & Files 3

DisplayingFileTypes
> Usethefile commandtodeterminecertainfiletypes.
> Theoutputfromthefilecommandcanbe:
Text
Data
Executableorbinary

44

22

11/29/2010

UNIX Fundamentals

Viewing Directories & Files 3

ChangingDirectories
> Youcanchangeyourcurrentworkingdirectoryat
anytimeusingthecd command
> Youcanusepathnameabbreviationstoeasily
navigate
> orrefertodirectoriesonthecommandline

45

UNIX Fundamentals

Viewing Directories & Files 3

ChangingDirectories

> Thisfigureshowsthedir1 directoryandits


parentdirectory, theuser1 directory.
$cd /export/home/user1
> or
$cd ..
46

23

11/29/2010

UNIX Fundamentals

Viewing Directories & Files 3

Returningtoyourhomedirectory
$
$
$
$

cd
cd ~user1/
cd ~/
cd $HOME

47

UNIX Fundamentals

Viewing Directories & Files 3

WorkingWithFiles
> Therearedifferentcommandsavailablethatenable
youto viewfilecontentinareadonlyformatorto
display informationaboutafile.
> Thesecommandsinclude:
Thecat command
Themore command
Thetail command
Thehead command
Thewc command
48

24

11/29/2010

UNIX Fundamentals

Viewing Directories & Files 3

ViewingFilesUsingthemore Command
> Whenthe--More--(n%) promptappears,you
canusethe keysdescribedinthefollowingtableto
scrollthroughthefile.

49

UNIX Fundamentals

Viewing Directories & Files 3

ViewingFilesUsingthemore Command
> cat/var/log/messages
> cat/var/log/messages|more
> more/var/log/messages

50

25

11/29/2010

UNIX Fundamentals

Viewing Directories & Files 3

DisplayingLine, Word,andCharacter Counts


> Usethewc commandtodisplaythenumberoflines,
words,andcharacterscontainedinafile.
> Thistableshowstheoptionsthatyoucanusewith
thewc command.

51

UNIX Fundamentals

Viewing Directories & Files 3

ViewingFileContentUsinghead
> Usethehead commandtodisplaythefirst10lines
ofafile.
> Youcanchangethenumberoflinesdisplayedusing
the-n option.
> The-n optiondisplaysn linesstartingatthe
beginningofthefile.

52

26

11/29/2010

UNIX Fundamentals

Viewing Directories & Files 3

ViewingFileContentUsingtail
> Usethetail commandtodisplaythelast10lines
ofafile.
> Youcanchangethenumberoflinesdisplayedusing
the-n or+n options.
> The-n optiondisplaysnlinesfromtheendofthe
file.
> The+n optiondisplaysthefilefromlinentotheend
ofthefile

53

UNIX Fundamentals

Viewing Directories & Files 3

Examples
$
$
$
$
$
$
$
$
$

cat /etc/passwd
tail -2 /etc/passwd
head -2 /etc/passwd
ls R / > dat
cat ./dat
more ./dat
cat ./dat | more
wc /etc/passwd
wc l /etc/passwd

54

27

11/29/2010

UNIX Fundamentals

Viewing Directories & Files 3

ViewingFileContentUsingtail
> Usethetail commandtodisplaythelast10lines
ofafile.
> Youcanchangethenumberoflinesdisplayedusing
the-n or+n options.
> The-n optiondisplaysnlinesfromtheendofthe
file.
> The+n optiondisplaysthefilefromlinentotheend
ofthefile

55

Omega
Training & Consultancy

Module 4

Working with
Directories
and Files

28

11/29/2010

UNIX Fundamentals

Working with Directories & Files 4

CopyingFiles
> Thesyntaxforthecp commandwhencopyingfilesis:
cp -option sources target
> Thesourceoptionisafile.
> Thetargetoptioncanbeafileoradirectory.
> Thistabledescribessomeoptionsyoucanusewith
the cp commandwhenyouarecopyingfilesand
directories.

57

UNIX Fundamentals

Working with Directories & Files 4

CopyingFiles
$
$
$
$

touch apple
ls
cp apple pear
ls

58

29

11/29/2010

UNIX Fundamentals

Working with Directories & Files 4

CopyingMultipleFiles

$ cd
$ cp feathers* dir1/
59

Working with Directories & Files 4

UNIX Fundamentals

MovingandRenamingFiles&Directories
> Youcanusethemv commandto:
Moveandrenameafile
Moveafiletoanotherdirectory
Moveadirectoryanditscontents
Renameadirectory

60

30

11/29/2010

Working with Directories & Files 4

UNIX Fundamentals

MovingandRenamingFiles&Directories
$
$
$
$
$
$
$
$
$
$
$

cd
touch banana
ls
mv banana apricot
ls
mkdir dir3
ls
mv apricot dir3/
ls
ls dir3/
mv dir3 dir4
61

Working with Directories & Files 4

UNIX Fundamentals

MovingandRenamingFiles&Directories
$
$
$
$

mkdir dir5
mv dir4 dir5
ls dir5
ls R .

62

31

11/29/2010

Working with Directories & Files 4

UNIX Fundamentals

CreatingFilesandDirectories
> Youcanusethetouch andmkdir commandsto:
Createemptyfiles
Createdirectories

63

Working with Directories & Files 4

UNIX Fundamentals

CreatingFilesandDirectories
$ cd
$ mkdir newdir
$ mkdir Reports

64

32

11/29/2010

Working with Directories & Files 4

UNIX Fundamentals

CreatingFilesandDirectories
$
$
$
$
$
$
$
$

cd
mkdir DIR1
ls
mkdir DIR1/DIR2
ls
cd DIR1
ls
pwd

$ mkdir p DIR1/DIR2

65

Working with Directories & Files 4

UNIX Fundamentals

RemovingFilesandDirectories
> Fromthedirectoryhierarchyyoucanpermanently:
Removefiles
Removedirectories(includingremovingadirectory
withcontent)
> Thistabledescribestheoptionsthatyoucanusewith
therm commandwhenyouareremovingdirectories.

66

33

11/29/2010

Working with Directories & Files 4

UNIX Fundamentals

RemovingFilesandDirectories
$
$
$
$
$
$
$
$
$
$

cd
mkdir fruit
touch fruit/banana
touch fruit/apple
cd fruit
touch pear
touch pricot
ls
rm apple
ls

$
$
$
$
$

rm pear
ls
cd ..
rm r fruit/
ls

67

Omega
Training & Consultancy

Module 5

The vi Editor

34

11/29/2010

The vi Editor 5

SOLARIS 10 Fundamentals

69

SOLARIS 10 Fundamentals

The vi Editor 5

InputCommandsforthevi Editor
> Commandsthatyoucanusetoinsertandappendtext
toafileusingthevieditorareshowninthistable.

70

35

11/29/2010

SOLARIS 10 Fundamentals

The vi Editor 5

MovingtheCursorWithinthevi Editor

71

SOLARIS 10 Fundamentals

The vi Editor 5

MovingtheCursorWithinthevi Editor

72

36

11/29/2010

SOLARIS 10 Fundamentals

The vi Editor 5

TextDeletionCommandsforthevi Editor

73

SOLARIS 10 Fundamentals

The vi Editor 5

EditCommandsforthevi Editor
> Commandstochangetext,undoachange,andrepeat
aneditfunctioninthevi editorareshowninthis
table.Manyofthesecommandschangethevi editor
toinputmode.Toreturntocommandmode,press
Esc key.

74

37

11/29/2010

SOLARIS 10 Fundamentals

The vi Editor 5

EditCommandsforthevi Editor

75

SOLARIS 10 Fundamentals

The vi Editor 5

SearchandReplaceCommands

76

38

11/29/2010

SOLARIS 10 Fundamentals

The vi Editor 5

CopyandPasteCommands
> Commandsthatyank(yy)andput(p,P)textinthevi
editorarelistedhere.

77

SOLARIS 10 Fundamentals

The vi Editor 5

AdditionalCopyandPasteCommands
> Additionalcommandsthatcopy(co)andmove(m)
textinthevi editorarelistedhere.

78

39

11/29/2010

SOLARIS 10 Fundamentals

The vi Editor 5

SaveandQuitCommands
> Commandsthatsavethefileandquitthevieditorare
showninthefollowingtable.

79

SOLARIS 10 Fundamentals

The vi Editor 5

EditSessionCustomizationCommands
> Variablesofthesetcommandincludedisplayingline
numbersandinvisiblecharacters,suchastheTaband
theendoflinecharacters.

80

40

11/29/2010

SOLARIS 10 Fundamentals

The vi Editor 5

Customizingthevi editor
> $HOME/.exrc
:setnu
abbr kurt bkurt@itu.edu.tr
abbr _html <html><body></body></html>
map #3 ZZ
map #5 dd
map sil :1,$d<Return>
81

Omega
Training & Consultancy

Module 6

Using
Commands
Within the Shell

41

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

UsingtheShellMetacharacters
> Pathnamemetacharactersinclude:
Thetilde(~)character
Thetilde(~)characterwithausername
> Filenamesubstitutionmetacharactersinclude:
Theasterisk(*)character
Thequestionmark(?)character
Thesquarebracket([])characters

83

Using Commands within the Shell 6

UNIX Fundamentals

UsingtheShellMetacharacters
>
>
>
>
>

ls file*
ls file?
ls file[abc1257]
ls [fp]*
ls [af]*

84

42

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

UsingtheShellMetacharacters
> 3digit files:
$touch {1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
{0,1,2,3,4,5,6,7,8,9}
> Evennumbered filenames:
$ls [09]*[02468]
> Oddnumbered filenames:
$ls [09]*[13579]

85

Using Commands within the Shell 6

UNIX Fundamentals

Tilde(~)Character
> Thetilde(~)characterrepresentsthehomedirectory
ofthecurrentuser.
> Itisasubstitutionthatequatestotheabsolutepath
nameoftheuser.
$cd ~/
$pwd
$cd ~gandalf/
$pwd

86

43

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

Asterisk(*)Character
> Theasterisk(*)characterisalsocalledthewildcard
characterandrepresentszeroormorecharacters,
excepttheleadingperiod(.)ofahiddenfile.
$cd
$ls f*
feathers file.1 file.2 file.3 file4 fruit2
feathers_6 file1 file2 file3 fruit

87

Using Commands within the Shell 6

UNIX Fundamentals

Asterisk(*)Character
$ls d*
dante dante_1
dir1:
coffees fruit trees
dir2:
beans notes recipes
dir3:
cosmos moon planets space sun vegetables
dir4:
constellation memo roses
dir5:
dir10:
planets
88

44

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

Asterisk(*)Character
$ls *3
file.3 file3
dir3:
cosmos moon planets space sun vegetables

89

Using Commands within the Shell 6

UNIX Fundamentals

QuestionMark(?)Character
> Thequestionmark(?)characterrepresentsanysingle
characterexcepttheleadingperiod(.)ofahiddenfile.
$ls dir?
dir1:
coffees fruit trees
dir2:
beans notes recipes
dir3:
cosmos moon planets space sun vegetables
dir4:
constellation memo roses
dir5:
90

45

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

Dash()Character
> Thedash()characterintheshellrepresentsthe
previousworkingdirectory.
> Youcanusethedashcharactertoswitchbetweentwo
specificdirectories.Theshellautomaticallydisplays
thecurrent
$cd /etc
$pwd
$cd /tmp
$pwd

$cd
$pwd
$cd
$pwd
91

Using Commands within the Shell 6

UNIX Fundamentals

SquareBracket([])Characters
> Thesquarebracket([])charactersrepresentasetor
rangeofcharactersforasinglecharacterposition.
> Asetofcharactersisanynumberofspecific
characters;forexample,[acb].Thecharactersinaset
donotgenerallyneedtobeinanyorder:
[abc]isthesameas[cab].
> Arangeofcharactersisaseriesoforderedcharacters.
Arangeliststhefirstcharacter,ahyphen(),andthe
lastcharacter:[az]or[09].
92

46

11/29/2010

UNIX Fundamentals

Using Commands within the Shell 6

SquareBracket([])Characters
$ls [af]*
brands dante_1 file.1 file2 file4
celery feathers file1 file.3 fruit
dante feathers_6 file.2 file3 fruit2
dir1:
coffees fruit trees
dir10:
planets
dir2:
beans notes recipes
dir3:
cosmos moon planets space sun vegetables
dir4:
93

UNIX Fundamentals

Using Commands within the Shell 6

SquareBracket([])Characters
$ls [fp]*
feathers file.1 file.2 file.3 file4 fruit2
feathers_6 file1 file2 file3 fruit
perm:
group motd skel vfstab
practice1:
appointments file.1 file.2 play

94

47

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

IntroducingShellVariables
> Avariablereferstoatemporarystorageareain
memory.Variablescontain:
Informationneededforcustomizingtheshell
Informationneededbyotherprocessestofunction
properly
> Theshellenablesyoutostorevaluesinvariables.
> Shellprogrammingusestwotypesofvariables:
Variablesthatareexportedtosubshells
Variablesthatarenotexportedtosubshells
95

Using Commands within the Shell 6

UNIX Fundamentals

ShellCommandsforVariables
> Shellcommandsusedtoset,unset,andview
variables:

96

48

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

DefaultKornShellVariables

97

Using Commands within the Shell 6

UNIX Fundamentals

ReferencingValuesinVariables
> Youcanusetheechocommandtodisplaythevalue
thatisstoredinsideashellvariable.
> Forexample:
$echo$SHELL
/bin/ksh

98

49

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

DisplayingVariables
> Tolistallshellvariableswiththeircurrentvalues,
performthesetcommand:
$set
DISPLAY=:0.0
EDITOR=/usr/bin/vi
ERRNO=13
FCEDIT=/bin/vi
HOME=/export/home/student
HZ=100
IFS=
LANG=C
LINENO=1
...

99

Using Commands within the Shell 6

UNIX Fundamentals

export
> Tomakethevalueofavariableknowntoasubshell,
exportitusingtheexportcommand.
> Toviewalistofallthesevariablesandtheircurrent
values,performtheexportcommand:
$export
DISPLAY=:0.0
EDITOR=/usr/bin/vi
ERRNO=13
FCEDIT=/bin/vi
HOME=/export/home/student
HZ=100
...
100

50

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

SettingandUnsettingShellVariables
> Avariableissetandavalueisassignedwiththe
followingsyntax:
> var=value
$ private=/export/home/student/private
$ set| grep private
private=/export/home/student/private
$ cd $private; pwd
/export/home/student/private

101

Using Commands within the Shell 6

UNIX Fundamentals

SettingandUnsettingShellVariables
> Tomakethevalueofavariableknowntoasubshell,
usethefollowingcommandsyntax:
> exportVAR
$exportoffice=/export/home/student/office
$echo$office
/export/home/student/office

102

51

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

SettingandUnsettingShellVariables
> Youcandeletethevaluesstoredinshellvariableswith
thefollowingcommandsyntax:
unsetVAR

$unsetprivate
$echo$private

103

Using Commands within the Shell 6

UNIX Fundamentals

CustomizingKornShellVariables
> ThePS1promptvariable
> ThePATHvariable
> ExtendingthePATHvariable

104

52

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

ThePS1PromptVariable
> Theshellpromptstringisstoredintheshellvariable
PS1,andyoucancustomizeitaccordingtoyour
preferences.
$PS1=$LOGNAME@unamen \$PWD$
student@host1:$

105

Using Commands within the Shell 6

UNIX Fundamentals

ThePS1PromptVariable
$ILU=IlikeUNIX
$PS1=$ILU >
ILikeUNIX>echo$ILU
IlikeUNIX
IlikeUNIX>

106

53

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

ThePATHVariable
> ThePATHvariablecontainsalistofdirectorypath
names,separatedbycolons.
> Whenyouperformacommandonthecommandline,
theshellsearchesthesedirectoriesfromlefttoright
tolocatethatcommand.
> Theshellexecutesthefirstcommandthatitfinds.
> Iftheshelldoesnotfindthecommandinanyofthe
listeddirectories,itdisplaysthefollowingerror
message:
ksh:command_name:notfound
107

Using Commands within the Shell 6

UNIX Fundamentals

ExtendingthePATHVariable
$echo$PATH
/usr/dt/bin:/usr/openwin/bin:/usr/bin

$
$PATH=$PATH:~
$
$echo$PATH
/usr/dt/bin:/usr/openwin/bin:/usr/bin:/export/home/student

108

54

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

UsingtheQuotingCharacters
> Quotingisaprocessthatinstructstheshelltomask,
orignore,thespecialmeaningofmetacharacters.
> Thequotingcharactersare
singleforwardquotationmarks(),
doublequotationmarks(""),
backslash(\),
parentheses($(command)).

109

Using Commands within the Shell 6

UNIX Fundamentals

UsingtheQuotingCharacters
> Quotationmarksaroundastringofmetacharacters
preventtheshellfrominterpretingthespecial
meaningofthemetacharacters.
> Therearetwotypesofquotationmarksthatmaskthe
specialmeaningofmetacharacters:
singleforwardquotationmarks():instructthe
shelltoignoreallenclosedmetacharacters.
doublequotationmarks("").

110

55

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

UsingtheQuotingCharacters
> Doublequotationmarksinstructtheshelltoignoreall
enclosedmetacharacters,exceptforthefollowing
threecharacters:
Thesinglebackwardquotationmarks() Single
backwardquotationmarksinstructtheshellto
executeanddisplaytheoutputforaUNIXsystem
command.
Thebackslash(\) Abackslash(\)characterinfront
ofametacharacterpreventstheshellfrom
interpretingthenextcharacterasametacharacter.
111

Using Commands within the Shell 6

UNIX Fundamentals

UsingtheQuotingCharacters
> Doublequotationmarksinstructtheshelltoignoreall
enclosedmetacharacters,exceptforthefollowing
threecharacters:
Thedollarsign($) Youcanalsouseparentheses()
toperformcommandsubstitution.Parentheses($
(command))instructstheshelltoexecuteand
displaytheoutputforthecommandenclosed
within.

112

56

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

UsingtheQuotingCharacters
$echo$SHELL
$SHELL
$echo"$SHELL"
/bin/ksh
$echo"\$SHELL"
$SHELL
$echoTodaysdateisdate
TodaysdateisWedJan2021:26:33IST2008
$echoTheuseriscurrentlyinthe$(pwd)directory.
113

Using Commands within the Shell 6

UNIX Fundamentals

DisplayingtheCommandHistory
> Usethehistorycommand
> Usethercommand
> Editandrerunpreviouslyexecutedcommands

114

57

11/29/2010

UNIX Fundamentals

Using Commands within the Shell 6

UsingthehistoryCommand
> Thehistorycommanddisplayspreviouslyexecuted
commands.
> Bydefault,thehistorycommanddisplaysthelast16
commandstothestandardoutput.
$history
...
87 date
88 cd /etc
89 touch dat1 dat2
90 ps -ef
91 history
115

Using Commands within the Shell 6

UNIX Fundamentals

UsingthehistoryCommand
> Thecommandsarerecordedinyour.sh_history file.
> Theoutputcanincludecommandsfrommultiple
windows.

116

58

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

UsingthehistoryCommand
> Todisplaythecommandhistorywithoutlinenumbers,
performthefollowingcommand:
$historyn
...
date
cd /etc
touchdat1dat2
ps ef
history
117

Using Commands within the Shell 6

UNIX Fundamentals

UsingthehistoryCommand
> Todisplaythecurrentcommandandthefour
commandsprecedingit,performthefollowing
command:
$history4
107date
108cd /etc
109touchdat1dat2
110ps ef
111history
118

59

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

UsingthehistoryCommand
> Todisplaythehistorylistinreverseorder,performthe
followingcommand:
$historyr
111history
110ps ef
109touchdat1dat2
108cd /etc
107date
...
119

UNIX Fundamentals

Using Commands within the Shell 6

UsingtherCommand
> ThercommandisanaliasbuiltintotheKorn shellthat
enablesyoutorepeatacommand.
> Torepeatthecalcommandusingthercommand,
performthefollowingcommand:
$cal
$r
February 2008
S M Tu W Th F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29

cal
February 2008
S M Tu W Th F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29

120

60

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

UsingtherCommand
> Toreexecuteacommandbylinenumber,usether
commandfollowedbytherespectivelinenumber:
$history
155history
156catdante
157history
158date
159cal
160ls
161cd

$r160
(outputomitted)
121

UNIX Fundamentals

Using Commands within the Shell 6

UsingtherCommand
> Youcanalsousethercommandtoreexecutea
commandbeginningwithaparticularcharacter,or
stringofcharacters.
> Torerunthemostrecentoccurrenceofacommand
thatbeginswiththeletterc,performthefollowing
command:
$rc
cd /etc

> Torerunthemostrecentoccurrenceoftheps
command,performthefollowingcommand:
$rps
ps ef

122

61

11/29/2010

UNIX Fundamentals

Using Commands within the Shell 6

UsingCommandRedirection
> Shellmetacharacters enablecommandredirection,as:
Thefiledescriptors
Redirectionofstandardinput
Redirectionofstandardoutput
Redirectionofstandarderror
Thepipecharacter

123

UNIX Fundamentals

Using Commands within the Shell 6

UsingCommandRedirection
> Youcanredirectinputtoandoutputfromcommands
usingredirection.
> Therearetworedirectioncommands:thegreater
than(>)andthelessthan(<)metacharacters.
> Typically,theshellreceivesorreadscommandinput
fromthekeyboard,anddisplaysorwritesthe
commandoutputtothescreen.

124

62

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

TheFileDescriptors
> Eachprocessthattheshellcreatesworkswithfile
descriptors.
> Filedescriptorsdeterminewheretheinputtothe
commandoriginatesandwheretheoutputanderror
messagesaresent.

125

Using Commands within the Shell 6

UNIX Fundamentals

RedirectingStandardInput
> Thefollowingsyntaxexampleshowsacommandusing
thelessthan(<)metacharacter toprocessafileasthe
standardinputinsteadofreadingtheinputfromthe
keyboard:

command<filename
command0<filename

126

63

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

RedirectingStandardOutput
> Thefollowingsyntaxexampleshowsacommandusing
thegreaterthan(>)metacharacter todirectthe
standardoutputtoafileinsteadofprintingtheoutput
tothescreen.Iffiledoesnotexist,thesystemcreates
it.
> Ifthefileexists,theredirectionoverwritesthe
contentsofthefile.

command>filename
command1>filename
127

Using Commands within the Shell 6

UNIX Fundamentals

RedirectingStandardOutput
> Thefollowingexampleshowsacommandusingtwo
greaterthan(>>)characterstodirectthestandard
outputtotheendofexistingcontentinafile.
> Thestandardoutputgetsappendedtotheexisting
content.Ifthefiledoesnotexist,thesystemcreates
it.

command>> filename

128

64

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

RedirectingStandardError
> Thefollowingexampleshowsacommandusingthe
filedescriptornumber(2)andthegreaterthan(>)
charactertoredirectanystandarderrormessagesto
the/dev/nullfile.
> Thisredirectionisusefultosuppresserrormessages
sothatnoerrormessagesappearonthescreen.

command2>/dev/null

129

Using Commands within the Shell 6

UNIX Fundamentals

RedirectingStandardError
> Thefollowingexampleshowsacommandredirecting
thestandardoutputtoafileandthestandarderrorto
thesamefile.
> Thesyntax2>&1instructstheshelltoredirectstderr
(2)tothesamefilethatreceivesstdout (1).

command1>filename2>&1

130

65

11/29/2010

UNIX Fundamentals

Using Commands within the Shell 6

ThePipeCharacter
> Thefollowingexampleshowsacommandusingthe
pipe(|)charactertoredirectthestandardoutputto
thestandardinputofanothercommand:

command | command
> Youcaninsertapipecharacterbetweenanytwo
commandsthefirstcommandwritestheoutputto
standardoutputandthesecondcommandreads
standardoutputfromthepreviouscommandas
standardinput.
$who|wc l
35

131

Using Commands within the Shell 6

UNIX Fundamentals

WorkingWithUserInitializationFiles
> Basedontheshell,theremightbeeitheroneortwo
defaultinitializationfilesinyourhomedirectorythat
enableyoutocustomizeyourworkingenvironment.

132

66

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

BourneShellInitializationFile
> The.profilefileisaninitializationfilethatyoudefine
inyourhomedirectory.
> Theloginshellexecutesthe.profilefilewhenyoulog
in.
> Youcancustomizeenvironmentvariablesand
terminalsettingsinthe.profilefiletomodifyyour
workingenvironment.
> Youcanalsoinstructthesystemtoinitiate
applicationsinthe.profilefile.
133

Using Commands within the Shell 6

UNIX Fundamentals

KornShellInitializationFiles
> TheKorn shellemploystwoinitializationfiles.
.profilefile
.kshrc file

134

67

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

The~/.profileFile
> The.profilefileisaninitializationfilethatresidesin
yourhomedirectory.
> Theloginprocessrunsthe.profilefilewhenyoulogin.
Youcancustomizeenvironmentvariablesand
terminalsettingsinthethisfiletomodifyyour
workingenvironment.
> Youcanalsoinstructthesystemtoinitiate
applicationsinthe.profilefile.

135

Using Commands within the Shell 6

UNIX Fundamentals

The~/.kshrcFile
> The.kshrc fileinyourhomedirectorycontainsshell
variablesandaliases.
> Thesystemexecutesthe.kshrc fileeverytimeyoulog
inandwhenaksh subshellisstarted.
> ThisfileisusedtodefineKorn shellspecificsettings.
> Touseit,theENVvariablemustbedefinedinthe
.profilefile.

136

68

11/29/2010

Using Commands within the Shell 6

UNIX Fundamentals

The~/.kshrcFile
> Youtypicallyconfigurethefollowingsettingsinthe
.kshrc file:
Shellpromptdefinitions(PS1andPS2)
Aliasdefinitions
Shellfunctions
Historyvariables
Shelloptions(setooption)

137

Using Commands within the Shell 6

UNIX Fundamentals

SourcingaFile
> Whenyoumakechangestoyourindividual
initializationfiles,thechangestakeeffectthenext
timeyoulogin.
> However,ifyouwantthechangestotakeeffect
immediately,youcansourcethe.profilefileandthe
.kshrc fileusingthedot(.)command.
$.~/.profile
$
$.~/.kshrc
138

69

11/29/2010

Omega
Training & Consultancy

Module 7

Basic File
Permissions

UNIX Fundamentals

Basic File Permissions

ViewingPermissionCategories
> Toviewthepermissionsforfilesanddirectories,
performthels -l command:

140

70

11/29/2010

UNIX Fundamentals

Basic File Permissions

ViewingPermissionCategories
> Thefirstfieldofinformationdisplayedbythels l
commandisthefiletype.
> Thefiletypetypicallyspecifieswhetheritisafileora
directory.
> Afileisrepresentedbyahyphen()
> Adirectoryisrepresentedbytheletterd

141

UNIX Fundamentals

Basic File Permissions

TypesofUsers
> Thistabledescribeseachtypeofuserwithabrief
descriptionofeach.

142

71

11/29/2010

UNIX Fundamentals

Basic File Permissions

PermissionTypes
> Theownerpermissions:Theownerpermissionset
determinesthetypeofaccesstheownerhasforthe
fileordirectory.
> Thegrouppermissions:Thegrouppermissionset
determinesthetypeofsharedfileaccessforeachuser
belongingtothefileownersgroup.
> Theotherpermissions:Theotherpermissionset
determinesthetypeofaccessforallotheruserswho
haveaccesstothesystem,butwhodonotownthe
fileordirectory,andarenotamemberofthefilesor
directorysgroup
143

UNIX Fundamentals

Basic File Permissions

PermissionCharacters

144

72

11/29/2010

UNIX Fundamentals

Basic File Permissions

PermissionSets

145

UNIX Fundamentals

Basic File Permissions

Usingthels n Command
> Toviewtheuseridentifiers(UIDs)andgroup
identifiers (GIDs),performthels ncommandonthe
/var/adm directory.

146

73

11/29/2010

UNIX Fundamentals

Basic File Permissions

DescriptionoftheOutputofthels n Command

147

UNIX Fundamentals

Basic File Permissions

AssignedOctalValuesforPermissions
> Thistableshowstheoctalnumbersforeachindividual
permission.

148

74

11/29/2010

UNIX Fundamentals

Basic File Permissions

OctalDigitsforPermissionSets
> Thistableshowstheoctalnumbersthatrepresenta
combined setofpermissions.

149

UNIX Fundamentals

Basic File Permissions

CombinedValuesandPermissions
> Thistableshowsthepermissionsetsforthethree
digitoctal numbers:

150

75

11/29/2010

UNIX Fundamentals

Basic File Permissions

Changingpermissionsinsymbolicmode

151

UNIX Fundamentals

Basic File Permissions

Changingpermissionsinsymbolicmode
>
>
>
>
>
>
>

touch
ls n
chmod
ls n
chmod
chmod
ls n

apple
apple
g-rwx apple
apple
o-wx apple
o+r apple
apple

152

76

11/29/2010

UNIX Fundamentals

Basic File Permissions

Introducingtheumask Utility
> Thistableshowsthefileanddirectorypermissions
thatare createdforeachoftheumask octalvalues.
> Alsousethese valuestodeterminetheumask value
youwanttoset.

153

Omega
Training & Consultancy

Module 8

Access Control
Lists

77

11/29/2010

UNIX Fundamentals

Access Control Lists

AccessControlLists
> StandardUNIXfileprotectionprovidesread,write,
andexecutepermissionsforthethreeuserclasses:file
owner,filegroup,andothers.
> ACLsprovidegreaterdataaccesscontrolforeachfile
ordirectory.
> ACLsenableyoutocontrolfilepermissionsmore
finely.
> ACLsprovidebetterfilesecurityforthefileowner,file
group,other,specificusers,andspecificgroups.
155

UNIX Fundamentals

Access Control Lists

ACLCommands

156

78

11/29/2010

UNIX Fundamentals

Access Control Lists

ACLCommands

157

UNIX Fundamentals

Access Control Lists

ViewingACLEntries

158

79

11/29/2010

UNIX Fundamentals

Access Control Lists

ACLEntryTypes

159

UNIX Fundamentals

Access Control Lists

ACLEntryTypes

160

80

11/29/2010

UNIX Fundamentals

Access Control Lists

DeterminingifaFilehasanACL
> TherearetwowaystodetermineifafilehasanACL:
Usethegetfacl command
Usethels -l command
> Usingthels -l commandonanyfilethathasan
ACLdisplaysaplus(+)signattheendofthe
permissionmodefield
> Forexample:
$ls lfile2
rwrr+ 1studentclass0Jan2213:40file2
161

UNIX Fundamentals

Access Control Lists

ConfiguringorModifyinganACL
> Thefollowingexampleshowsyouhowtoaddanew
ACLentrytoafilewithexistingACLentries:
$ setfacl -m u:acluser2:7 file2
$ getfacl file2
# file: file2
# owner: student
# group: class
user::rwuser:
acluser:rwx #effective:r-user:acluser2:rwx #effective:r-group::r-- #effective:r-mask:r-other:r--

162

81

11/29/2010

UNIX Fundamentals

Access Control Lists

SubstitutinganACL
> ToreplacetheentireACLonafile,youmustspecifyat
leastthebasicsetofACLentries:user,group,other,
maskpermissions,andfilenames.Forexample:
$setfacl -s u::rwx,g::rw-,o:r--,m:rw-,u:acluser:rwx file1
$getfacl file1
# file: file1
# owner: student
# group: class
user::rwx
user:acluser:rwx #effective:rwgroup::
rw- #effective:rwmask:
rwother:
r--

163

UNIX Fundamentals

Access Control Lists

SwitchingUsersonaSystem
> Youcanusethesu commandtoswitchtoanother
userwithoutloggingoutandbackintothesystemas
thatuser:
su username
> Forexample:
$su user1
Password:<enteruser1spassword>
$whoami ;pwd
user1
/export/home/user1
$exit
164

82

11/29/2010

Omega
Training & Consultancy

Module 9

Searching Files
and Directories

UNIX Fundamentals

Searching Files & Directories

Usingthegrep Command
> Theoptionsthatyouusewiththegrep command
canmodify yoursearch.
> Eachoption,exceptforthew option,canbeused
withtheegrep andfgrep commands.

166

83

11/29/2010

UNIX Fundamentals

Searching Files & Directories

Usingthegrep Command
> Thegrep commandsupportsseveralregular
expressionmetacharacterstofurtherdefineasearch
pattern.
> Thetableonthefollowingslidesdescribessomeof
theregularexpressionmetacharacters.

167

UNIX Fundamentals

Searching Files & Directories

Usingthegrep Command
$
$
$
$

cat /etc/passwd | grep root


grep root /etc/passwd
xclock &
ps fe | grep xclock

168

84

11/29/2010

UNIX Fundamentals

Searching Files & Directories

RegularExpressionMetacharacters

169

UNIX Fundamentals

Searching Files & Directories

RegularExpressionMetacharacters

170

85

11/29/2010

UNIX Fundamentals

Searching Files & Directories

Usingtheegrep Command
> Theegrep commandsearchesthecontentsofoneor
morefilesforapatternusingextendedregular
expressionmetacharacters.
> Extendedregularexpressionmetacharactersinclude
theregularexpressionmetacharactersthatthegrep
commandusesalongwithsomeadditional
metacharacters.

171

ExtendedRegularExpression
Metacharacters

Searching Files & Directories

UNIX Fundamentals

172

86

11/29/2010

UNIX Fundamentals

Searching Files & Directories

Usingthefind Command
> The pathname, expression,and action
argumentsforthe find commandareshowninthe
table.

173

UNIX Fundamentals

Searching Files & Directories

ExpressionforthefindCommand
> Expressions thatyoucanusewiththefind
command.

174

87

11/29/2010

UNIX Fundamentals

ActionsforthefindCommand
Searching Files & Directories

> Action argumentsforthefindcommand.

175

UNIX Fundamentals

ActionsforthefindCommand
Searching Files & Directories

> Additionalactionargumentsforthefind command:

176

88

11/29/2010

UNIX Fundamentals

Searching Files & Directories

Usingthefind Command
$ find /etc name pas* print
$ find / -user kurt mtime -7 size 100
print
$ find / -name core exec rm {} \;

177

Omega
Training & Consultancy

Module 10

Basic Process
Control

89

11/29/2010

UNIX Fundamentals

Basic Process Control

10

SolarisOSProcesses
> EveryprogramyourunintheSolarisOScreatesa
process.
> Whenyouloginandstarttheshell,youstarta
process.
> Whenyouperformacommandorwhenyouopenan
application,youstartaprocess.
> Thesystemstartsprocessescalleddaemons.Daemons
areprocessesthatruninthebackgroundandprovide
services.Forinstance,thedesktoplogindaemon
(dtlogin)providesagraphicalpromptthatyouuseto
login.
179

UNIX Fundamentals

Basic Process Control

10

UsingaPID
> Everyprocesshasauniqueprocessidentification
number(PID),whichthekernelusestotrack,control,
andmanagetheprocess.

180

90

11/29/2010

UNIX Fundamentals

Basic Process Control

10

UsingProcessUIDandGIDNumbers
> EachprocessisassociatedwithaUIDandaGID.These
numbersindicatewhoownsaprocessanddetermine
thefunctionsofaprocess.
> GenerallytheUIDandGIDassociatedwithaprocess
arethesameastheUIDandGIDoftheuserwho
startedtheprocess.

181

UNIX Fundamentals

Basic Process Control

10

UnderstandingtheParentProcess
> Whenoneprocesscreatesanother,thefirstprocessis
consideredtobetheparentofthenewprocess.
> Thenewprocessiscalledthechildprocess.
> Whilethechildprocessruns,theparentprocesswaits.
> Whenthechildfinishesitstask,itinformstheparent
process.Theparentprocessthenterminatesthechild
process.
> Iftheparentprocessisaninteractiveshell,aprompt
appears,indicatingthatitisreadyforanew
command.
182

91

11/29/2010

UNIX Fundamentals

> Thistabledescribessomeoftheps commandoptions:

Basic Process Control

10

Optionsfortheps Command

183

UNIX Fundamentals

Basic Process Control

10

DisplayingaListingofAllProcesses
> Usetheps -ef commandtoviewalistingofallthe
processescurrentlyscheduledtorunonthesystem.
> Thefollowingexampledisplaysalistingofall
processes:
$ ps -ef | more
UID PID PPID C STIME TTY TIME CMD
root 0 0 0 Jan 23 ? 0:18 sched
root 1 0 0 Jan 23 ? 0:01 /etc/init root 2 0 0 Jan 23 ? 0:00 pageout
root 3 0 0 Jan 23 ? 17:47 fsflush
root 291 1 0 Jan 23 ? 0:00 /usr/lib/saf/sac -t 300
root 294 291 0 Jan 23 ? 0:00 /usr/lib/saf/ttymon
root 216 1 0 Jan 23 ? 0:00 /usr/lib/power/powerd
--More-184

92

11/29/2010

UNIX Fundamentals

Basic Process Control

10

ps ef CommandOutputDescription

185

UNIX Fundamentals

Basic Process Control

10

SearchingforaSpecificProcess
> Tosearchforaspecificprocess,youcancombinethe
ps andgrep commandsusingthepipe(|)
character:
$ps e|grep lp
217?0:00lpsched

> Youcanusethepgrep commandtosearchfor


specificprocessesbyname.
> Bydefault,thepgrep commanddisplaysthe
PIDofeveryprocessthatmatchesthecriteria
youspecifyonthecommandline.
186

93

11/29/2010

UNIX Fundamentals

Basic Process Control

10

OptionsforthepgrepCommand

187

UNIX Fundamentals

Basic Process Control

10

pgrep
> Thefollowingexampleshowshowtousethepgrep
commanddisplaythePIDofanyprocesswithaname
thatcontainsthestringlp:
$ pgrep lp
217
> Thefollowingexampleshowshowtousethepgrep
commandwiththe-l optiontodisplaythePIDand
nameofanyprocesswithanamethatcontainsthe
stringlp:
$ pgrep -l vold
217 vold
188

94

11/29/2010

UNIX Fundamentals

Basic Process Control

10

pgrep
> Thefollowingexampleshowshowtousethepgrep
commandwiththe-lt optiontodisplaythePID
andthenameofanyprocessassociatedwitha
terminalwindow:
$ pgrep -lt pts/2
697 ksh
> Thefollowingexampleshowshowtousethepgrep
commandwiththe-fl optionstodisplay:
$ pgrep -l mountd
155 automountd
$ pgrep -fl automountd
155 /usr/lib/autofs/automountd

189

UNIX Fundamentals

Basic Process Control

10

Usingtheptree Command
> Theptree commanddisplaysaprocesstreebased
ontheprocessIDthatwaspassedasanargumentto
thecommand.
> TheoutputhasthespecifiedPIDsorusers,withchild
processesindentedfromtheirrespectiveparent
processes.
> AnargumentofalldigitsistakentobeaPID,
otherwiseitisassumedtobeauserloginname.

190

95

Anda mungkin juga menyukai