You are on page 1of 161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

V3.1

cover

AIX6Basics
(CourseCodeAU13)

StudentNotebook
ERC10.0

IBMCertifiedCourseMaterial

StudentNotebook

Trademarks
Thereadershouldrecognizethatthefollowingterms,whichappearinthecontentofthis
trainingdocument,areofficialtrademarksofIBMorothercompanies:
IBMisaregisteredtrademarkofInternationalBusinessMachinesCorporation.
ThefollowingaretrademarksofInternationalBusinessMachinesCorporationintheUnited
States,orothercountries,orboth:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

1/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

AIX
MVS
Systemp

AIX5L
OS/2
Systemp5

CommonUserAccess
pSeries
400

PS/2isatrademarkorregisteredtrademarkofLenovointheUnitedStates,other
countries,orboth.
AdobeiseitheraregisteredtrademarkoratrademarkofAdobeSystemsIncorporatedin
theUnitedStates,and/orothercountries.
JavaandallJavabasedtrademarksaretrademarksofSunMicrosystems,Inc.inthe
UnitedStates,othercountries,orboth.
MicrosoftandWindowsaretrademarksofMicrosoftCorporationintheUnitedStates,other
countries,orboth.
UNIXisaregisteredtrademarkofTheOpenGroupintheUnitedStatesandother
countries.
LinuxisaregisteredtrademarkofLinusTorvaldsintheUnitedStates,othercountries,or
both.
Othercompany,product,orservicenamesmaybetrademarksorservicemarksofothers.

February2008Edition
TheinformationcontainedinthisdocumenthasnotbeensubmittedtoanyformalIBMtestandisdistributedonanasisbasiswithout
anywarrantyeitherexpressorimplied.Theuseofthisinformationortheimplementationofanyofthesetechniquesisacustomer
responsibilityanddependsonthecustomersabilitytoevaluateandintegratethemintothecustomersoperationalenvironment.While
eachitemmayhavebeenreviewedbyIBMforaccuracyinaspecificsituation,thereisnoguaranteethatthesameorsimilarresultswill
resultelsewhere.Customersattemptingtoadaptthesetechniquestotheirownenvironmentsdosoattheirownrisk.
CopyrightInternationalBusinessMachinesCorporation1995,2008.Allrightsreserved.
ThisdocumentmaynotbereproducedinwholeorinpartwithoutthepriorwrittenpermissionofIBM.
NotetoU.S.GovernmentUsersDocumentationrelatedtorestrictedrightsUse,duplicationordisclosureissubjecttorestrictions
setforthinGSAADPScheduleContractwithIBMCorp.

V3.1.0.1
StudentNotebook

TOC

Contents
Trademarks...

..xi

CourseDescription...

.xiii

Agenda...

.xv

Unit1.IntroductiontoAIX...
UnitObjectives
AIXOperatingSystem...
WorkingonanAIXSystem(1of2)...
WorkingonanAIXSystem(2of2)...
Activity:FillintheBlanks...
TheShell:UserInterfacetoAIX
UsefulAIXUtilities...
AIXGraphicalUserInterfaces...
Checkpoint
UnitSummary...

.11
12
13
14
16
18
19
111
112
114
115

http://ss.hnu.cn/unix/ebook/aixbasics1.html

2/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Unit2.UsingtheSystem...
UnitObjectives
LoggingInandOut...
Passwords...
CommandFormat...
CommandFormatExamples...
ThedateandcalCommands
Theclear,echo,andbannerCommands
Activity:QuestionsandAnswers...
ThewhoandfingerCommands...
SendingMail...
ReceivingMail...
ThewriteandwallCommands...
talkwithAnotherUser...
mesg...
KeyboardTips...
Checkpoint
Exercise:UsingTheSystem...
UnitSummary...

.21
22
23
25
26
28
29
210
211
212
214
216
218
220
221
222
223
224
225

Unit3.AIX6.1Documentation...
UnitObjectives
manCommand...
manExample...
mank:WorkingwithaKeyword
ViewingAIX6.1Documentation...

.31
32
33
34
35
36

CopyrightIBMCorp.1995,2008

Contents

iii

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

AccessingtheDocumentsfromaWebBrowser
AIX6.1Documentation...
SearchAIX6.1Documentation
SearchScope...
Checkpoint...
Exercise:AIX6.1Documentation...
UnitSummary...
Unit4.FilesandDirectories...
UnitObjectives...
AFile...
FileTypes...
DirectoryContents
AIXFileSystems
HierarchicalStructure...
PathNames...
WhereAmI?...
ListingDirectories...
LongListingofFiles
ChangeCurrentDirectory...
Activity:Q+A...
CreatingDirectories
RemovingDirectories...
WorkingwithMultipleDirectories
DisplayingDirectoryInformation...
AIXFileNames...
touchCommand...
Checkpoint(1of2)...
Checkpoint(2of2)...
Exercise:FilesandDirectories...
UnitSummary...

http://ss.hnu.cn/unix/ebook/aixbasics1.html

..37
..38
..310
.311
.312
..313
.314
41
...42
.43
..44
..46
..48
..49
.411
.412
.413
...414
...416
.417
.418
..419
..420
..421
.422
...423
.424
.425
...426
.427

3/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Unit5.UsingFiles...
UnitObjectives...
CopyingFiles
cpExamples...
MovingandRenamingFiles...
mvExamples
ListingFileContents...
DisplayingFiles...
wcCommand...
Activity:WorkingwiththewcCommand...
LinkingFiles
LinkingFiles(cont.)...
RemovingFiles...
PrintingFiles...
Checkpoint...
Exercise:UsingFiles
iv

AIX6Basics

51
...52
..53
..54
...56
.57
..58
..59
.510
...511
...513
.514
.515
.516
.518
..519
CopyrightIBMCorp.1995,2008

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1.0.1
StudentNotebook

TOC

UnitSummary...

520

Unit6.FilePermissions...
UnitObjectives
LongListingofFiles
FileProtection/Permissions...
ChangingPermissions(SymbolicNotation)
ChangingPermissions(OctalNotation)
DefaultFilePermissions...
umask...
Activity:PersonalDirectories...
Function/PermissionsRequired
Checkpoint(1of3)
Checkpoint(2of3)
Checkpoint(3of3)
Exercise:FilePermissions
UnitSummary...

.61
62
63
65
66
68
610
611
613
615
616
617
618
619
620

Unit7.TheviEditor...
UnitObjectives
IntroductiontotheviEditor
Startingvi...
AddingText...
ExitingtheEditor...
CursorMovement...
DeletingText...
SearchforaPattern
Activity:viCommands...
ChangingText...
Cut,Copy,andPaste
viExecutingAIXCommands...
viOptions
CommandLineEditing
viEditors
Checkpoint
Exercise:viEditor
UnitSummary...

.71
72
73
75
76
77
78
710
711
712
713
715
717
719
721
723
724
725
726

Unit8.ShellBasics...
UnitObjectives
TheShell...
MetacharactersandWildcards
FileNameSubstitution(1of2)
FileNameSubstitution(2of2)

.81
82
83
84
85
86

http://ss.hnu.cn/unix/ebook/aixbasics1.html

4/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

TheStandardFiles
FileDescriptors...
InputRedirection...
OutputRedirection

88
89
810
811

CopyrightIBMCorp.1995,2008

Contents

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

.812
..813
.814
..816
.818
..819
.820
...821
..822
.823
.824
.825
.826

CreatingaFilewithcat.
Activity:ReviewShellBasics
ErrorRedirection...
CombinedRedirection
Pipes...
Filters
SplitOutputs...
CommandGrouping...
LineContinuation
Checkpoint(1of2)...
Checkpoint(2of2)...
Exercise:ShellBasics
UnitSummary...
Unit9.UsingShellVariables...
UnitObjectives...
ShellVariables
ListingVariableSettings...
SettingandReferencingShellVariables
ShellVariablesExample...
CommandSubstitution...
QuotingMetacharacters...
CommandLineParsing
Checkpoint(1of2)...
Checkpoint(2of2)...
Exercise:UsingShellVariables
UnitSummary...

91
...92
..93
..94
.95
..96
..97
..98
.99
.910
.911
..912
.913

Unit10.Processes...
UnitObjectives...
WhatIsaProcess?...
LoginProcessEnvironment...
ProcessEnvironment...
ParentsandChildren
VariablesandProcesses
Activity:ExportingVariables...
WhatIsaShellScript?...
InvokingShellScripts(1of3)...
InvokingShellScripts(2of3)...
InvokingShellScripts(3of3)...
ExitCodesfromCommands...
Checkpoint...
Activity:ShellScripts
UnitSummary...

101
..102
..103
..104
..105
..107
..109
.1010
..1014
...1015
...1016
...1017
.1018
...1019
..1020
.1022

Unit11.ControllingProcesses...
UnitObjectives...
MonitoringProcesses...
vi

AIX6Basics

111
..112
..113
CopyrightIBMCorp.1995,2008

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1.0.1
StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

5/161

11/25/2014

TOC

ss.hnu.cn/unix/ebook/aixbasics1.html

ControllingProcesses...
TerminatingProcesses(1of2)...
TerminatingProcesses(2of2)...
Signals...
RunningLongProcesses
JobControlintheKornShell...
JobControlExample...
Daemons...
Checkpoint
Exercise:ControllingProcesses...
UnitSummary...

114
116
117
119
1111
1113
1115
1116
1117
1118
1119

Unit12.CustomizingtheUserEnvironment...
UnitObjectives
LoginFiles...
Sample /etc/environment .
Sample/etc/profile ...
EnvironmentVariables(1of2)
Sample.profile ...
EnvironmentVariables(2of2)
Sample.kshrc ...
kshFeaturesAliases...
kshFeaturesUsingAliases
kshFeaturesHistory...
Checkpoint
Exercise:CustomizingtheUserEnvironment...
UnitSummary...

...121
122
123
125
126
127
128
129
1211
1212
1214
1215
1216
1217
1218

Unit13.AIXUtilities,PartI...
UnitObjectives
find...
SampleDirectoryStructure...
Usingfind...
ExecutingCommandswithfind...
InteractiveCommandExecution...
AdditionalOptions...
TheShellversusfind...
findExamples...
AIXUtilities(1)...
grep...
grepSampleDataFiles
Basicgrep...
grepwithRegularExpressions...
grepExamples
grepOptions...
OthergrepCommands...
Activity:grepCommand...
sortCommand...

...131
132
133
135
136
137
138
139
1310
1311
1312
1313
1314
1315
1316
1318
1319
1320
1322
1324

CopyrightIBMCorp.1995,2008

Contents

vii

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

sortExamples...
headandtailCommands...
telnet:LogintoRemoteHosts
ftp:TransfersFilesBetweenHosts...
ftpSubcommands...
rexec,rsh:NoninteractiveRemoteExecution
SecureShellUtilities(OpenSSH)...
tar:BackupandRestoreFiles...
Checkpoint...
Exercise:AIXUtilities(2)
http://ss.hnu.cn/unix/ebook/aixbasics1.html

...1325
...1326
...1328
...1329
...1330
..1331
.1333
..1335
...1336
..1337
6/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

UnitSummary...
Unit14.AIXUtilities,PartII...
UnitObjectives...
xargs.
xargsExamples...
xargs,find,andgrep...
ThelinksOptionwithfind...
aliasandfind...
which,whereis,andwhence.
file.
Exercise:AIXUtilities(3)
diff(DifferentialFileComparator)...
ComparingTwoFilesUsingdiff...
ComparingTwoFilesUsingcmp...
ComparingDirectoriesUsingdircmp...
compress,uncompress,andzcat...
DisplayingNonPrintableCharactersinFiles...
NonPrintableCharactersinDirectories...
AssigningUniqueFileNames...
Checkpoint...
Exercise:AIXUtilities(4)
UnitSummary...

.1338
141
..142
.143
...145
.146
...148
..149
...1410
.1412
..1414
...1415
..1416
..1418
.1419
..1421
..1423
..1424
.1425
...1426
..1427
.1428

Unit15.AdditionalShellFeatures...
UnitObjectives...
ImportantShellVariables...
PositionalParameters...
TheexprUtility...
exprExamples...
ConditionalExecution...
testCommand
ifCommand...
Activity:WritingShellScripts
readCommand
forLoopSyntax...
whileLoopSyntax...
CommandSearchOrder...

151
..152
.153
..154
...155
.157
.158
...159
...1510
..1512
...1514
...1515
...1516
...1517

viii

AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1.0.1
StudentNotebook

TOC

Sample.profile ...
Checkpoint
Exercise:AdditionalShellFeatures...
UnitSummary...
Unit16.TheAIXGraphicalUserInterface...
UnitObjectives
TheXWindowSystem...
WhatisAIXwindows?...
AnXWindowNetworkConfiguration
TheClient/ServerEnvironment...
XClients
TheXServer...
StartingAIXwindows...
StoppingX...
AnAIXwindowsDisplay...
TheaixtermWindow...
RunningaClientonAnotherSystem
ThexhostCommand...
ThexauthCommand...
CommonDesktopEnvironment(CDE)...
TheComponentsoftheCDEDesktop...

http://ss.hnu.cn/unix/ebook/aixbasics1.html

1518
1520
1521
1522
...161
162
163
165
166
168
169
1611
1612
1614
1615
1616
1618
1620
1622
1624
1626
7/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

TheLoginManager...
$HOME/.dtprofile...
FrontPanel
FrontPanelSubpanels...
FrontPanelFurtherControls...
TheStyleManager
TheFileManager
TheApplicationManager
ThePersonalApplicationsManager...
TheTerminalEmulator...
TheHelpSystem...
CheckpointQuestions(1of2)...
CheckpointQuestions(2of2)...
Exercise:UsingAIXwindowsandCDE...
UnitSummary...

1627
1628
1630
1632
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644

AppendixA.CheckpointSolutions...

..A1

AppendixB.CommandSummary...

..B1

AppendixC.CustomizingAIXwindows...

..C1

AppendixD.CDEUserCustomization...

..D1

Glossary...

.X1

CopyrightIBMCorp.1995,2008

Contents

ix

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

8/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

TMK

Trademarks
Thereadershouldrecognizethatthefollowingterms,whichappearinthecontentofthis
trainingdocument,areofficialtrademarksofIBMorothercompanies:
IBMisaregisteredtrademarkofInternationalBusinessMachinesCorporation.
ThefollowingaretrademarksofInternationalBusinessMachinesCorporationintheUnited
States,orothercountries,orboth:
AIX
MVS
Systemp

AIX5L
OS/2
Systemp5

CommonUserAccess
pSeries
400

PS/2isatrademarkorregisteredtrademarkofLenovointheUnitedStates,other
countries,orboth.
AdobeiseitheraregisteredtrademarkoratrademarkofAdobeSystemsIncorporatedin
theUnitedStates,and/orothercountries.
JavaandallJavabasedtrademarksaretrademarksofSunMicrosystems,Inc.inthe
UnitedStates,othercountries,orboth.
MicrosoftandWindowsaretrademarksofMicrosoftCorporationintheUnitedStates,other
countries,orboth.
UNIXisaregisteredtrademarkofTheOpenGroupintheUnitedStatesandother
countries.
LinuxisaregisteredtrademarkofLinusTorvaldsintheUnitedStates,othercountries,or
both.
Othercompany,product,orservicenamesmaybetrademarksorservicemarksofothers.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

9/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Trademarks

xi

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

xii

AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

10/161

11/25/2014

pref

ss.hnu.cn/unix/ebook/aixbasics1.html

CourseDescription
AIX6Basics
Duration:4days
Purpose
ThiscourseenablesstudentstoperformeverydaytasksusingtheAIX
operatingsystem.

Audience
ThiscourseissuitableforanyonewhorequiresbasicAIXuserskills.
Thiscourseisalsoaprerequisiteforstudentswhoplantoattendthe
AIXSystemAdministrationcourses.

Prerequisites
Studentsattendingthiscourseshouldbefamiliarwithbasic
informationtechnology(IT)conceptsandtheroleofanoperating
system.

Objectives
Aftercompletingthiscourse,youshouldbeableto:
LogintoanAIXsystemandsetauserpassword
UseAIXonlinedocumentation
ManageAIXfilesanddirectories
Describethepurposeoftheshell
Usethevieditor
ExecutecommonAIXcommandsandmanageAIXprocesses
Customizetheworkingenvironment
UsecommonAIXutilities
Writesimpleshellscripts
UsetheAIXWindowsenvironment
UsetheCommonDesktopEnvironment

CopyrightIBMCorp.1995,2008

CourseDescription

xiii

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Contents
IntroductiontoAIX
UsingtheSystem
AIX6.1Documentation
FilesandDirectories
UsingFiles
FilePermissions
TheviEditor
http://ss.hnu.cn/unix/ebook/aixbasics1.html

11/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

ShellBasics
UsingShellVariables
Processes
CustomizingtheUserEnvironment
AIXUtilities,PartI
AIXUtilities,PartII
AdditionalShellFeatures
TheAIXGraphicalUserInterface

Curriculumrelationship
ThiscourseisthefirstcourseintheAIXcurriculumandisa
prerequisiteforallthetrainingpaths.

xivAIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

pref

Agenda
Day1
Welcome
Unit1IntroductiontoAIX
Unit2UsingtheSystem
Exercise1UsingtheSystem
Unit3AIXDocumentation
Exercise2AIXDocumentation
Unit4FilesandDirectories
Exercise3FilesandDirectories
Unit5UsingFiles
Exercise4UsingFiles

Day2
Unit6FilePermissions
Exercise5FilePermissions
Unit7TheviEditor
Exercise6TheviEditor
http://ss.hnu.cn/unix/ebook/aixbasics1.html

12/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Unit8ShellBasics
Exercise7ShellBasics
Unit9UsingShellVariables
Exercise8UsingShellVariables

Day3
Unit10Processes
Unit11ControllingProcesses
Exercise9ControllingProcesses
Unit12CustomizingtheUserEnvironment
Exercise10CustomizingtheUserEnvironment
Unit13AIXUtilities,PartI
Exercise11AIXUtilities(1)
Unit13AIXUtilities,PartI(Continued)
Exercise12AIXUtilities(2)
Unit14AIXUtilities,PartII
Exercise13AIXUtilities(3)

CopyrightIBMCorp.1995,2008

Agenda

xv

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Day4
Unit14AIXUtilities,PartII(Continued)
Exercise14AIXUtilities(4)
Unit15AdditionalShellFeatures
Exercise15AdditionalShellFeatures
Unit16TheAIXGraphicalUserInterface

http://ss.hnu.cn/unix/ebook/aixbasics1.html

13/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

xviAIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

pref

Texthighlighting
Thefollowingtexthighlightingconventionsareusedthroughoutthisbook:
Bold

Identifiesfilenames,filepaths,directories,usernames,and
principals.

Italics

IdentifieslinkstoWebsites,publicationtitles,andisused
wherethewordorphraseismeanttostandoutfromthe
surroundingtext.

Monospace

Identifiesattributes,variables,filelistings,SMITmenus,code
examplesoftextsimilartowhatyoumightseedisplayed,
examplesofportionsofprogramcodesimilartowhatyoumight
writeasaprogrammer,andmessagesfromthesystem.

MonospaceboldIdentifiescommands,daemons,menupaths,andwhattheuser
wouldenterinexamplesofcommandsandSMITmenus.
<text>

Thetextbetweenthe<and>symbolsidentifiesinformationthe
usermustsupply.Thetextmaybenormalhighlighting,bold or
monospace,ormonospacebolddependingonthecontext.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

14/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
CopyrightIBMCorp.1995,2008

Agenda

xvii

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

xviiiAIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Unit1.IntroductiontoAIX

http://ss.hnu.cn/unix/ebook/aixbasics1.html

15/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

WhatThisUnitIsAbout
ThisunitisanintroductiontothecourseAIX6Basics.

WhatYouShouldBeAbletoDo
Aftercompletingthisunit,studentsshouldbeableto:
DescribethemajorcomponentsofanAIXsystem
Describethemajortopicsinthiscourse
ExplainthevalueofthesetopicswhenworkinginanAIX
environment

HowYouWillCheckYourProgress
Accountability:
Studentactivity
Checkpointquestions

CopyrightIBMCorp.1995,2008

Unit1.IntroductiontoAIX

11

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

UnitObjectives
Aftercompletingthisunit,youshouldbeableto:
Describethemajorcomponents ofanAIXsystem
Describethemajortopics inthiscourse
Providethevalue ofthesetopicswhenworkinginanAIX
http://ss.hnu.cn/unix/ebook/aixbasics1.html

16/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

environment

CopyrightIBMCorporation2008

Figure11.UnitObjectives

AU1310.0

Notes:

12AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

AIXOperatingSystem

Interfacetohardware

AIXKernel
Managesprocesses
Process1

Usersarah

Process2
Process3

Userfred

Process4

CopyrightIBMCorporation2008

http://ss.hnu.cn/unix/ebook/aixbasics1.html

17/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
Figure12.AIXOperatingSystem

AU1310.0

Notes:
TheAIXKernel
Acomputerconsistsofmanyhardwaredevicesthattheusersofacomputersystem
wanttouse.Forexample,theywanttoprintdocumentsortheywanttoplayagame
fromaCDROM.
Tocontrolthesehardwaredevicesandtosharethembetweenmultipleusers,an
operatingsystemmustbeloadedduringthesystemstartup.InthecaseoftheAIX
operatingsystem,thereisonespecialprogramwhichinterfacesdirectlytothe
hardwaredevices:theAIXKernel.TheKernelcontrolstheaccesstothedevices.
Ontheotherhand,theusersstartdifferentprograms,forexample,aprogramthatprints
adocumentorremovesafile.TheseprogramsthatruninAIXprocessesarealso
controlledbytheAIXKernel.
Tosayitsimply:TheAIXKernelistheheartofyouroperatingsystem.

CopyrightIBMCorp.1995,2008

Unit1.IntroductiontoAIX

13

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

WorkingonanAIXSystem(1of2)
LogintoAIX

Shell

$command1
$command2

$who
$mailsarah

$manmail
$infocenter

Workingwiththe
Shell

Communicate
withothers

Gettinghelp

CopyrightIBMCorporation2008

Figure13.WorkingonanAIXSystem(1of2)

AU1310.0

Notes:
Login
AIXisamultiusersystem.BeforeausercanworkwithAIX,anauthenticationprocess
takesplace.Theusermustloginwiththeusersusernameandpassword.

Theshell
http://ss.hnu.cn/unix/ebook/aixbasics1.html

18/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Afterasuccessfulauthentication,AIXstartsacertainprogramfortheuser,ashell.The
shellisacommandinterpreterthatwaitsforinputandexecutesthecommandsand
programstheusertypesin.Asyouwilllearninthiscourse,theshellisnotonlya
commandinterpreteritoffersgreatflexibility.Workingwiththeshellisoneofthemajor
topicsinthiscourse.

14AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty Communication
MultipleuserscanworkatthesametimeonanAIXsystemorinanetwork.Oneofthe
basictasksinyourdailyworkistocommunicatewithotherusersonasystemorinthe
network.Inthiscourse,youwilllearndifferentcommandsthatallowcommunication
withotherusers.

Additionalinformation
AIXoffersawiderangeoftoolsandcommands.Therearemultiplewaystoobtain
assistancewithcommandsforexample,themancommandortheAIXOnline
Documentation.Howtoworkwiththesehelptoolsisalsoamajortopicinthiscourse.

CopyrightIBMCorp.1995,2008

http://ss.hnu.cn/unix/ebook/aixbasics1.html

Unit1.IntroductiontoAIX

15

19/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

WorkingonanAIXSystem(2of2)
CDROM

Disks

FileSystem

DATA

Network

Workingwith
directories

Workingwithfiles
Copy,Move,Delete

Protect

Edit,Print

The vieditorisavailable
onmostUNIXplatforms
CopyrightIBMCorporation2008

Figure14.WorkingonanAIXSystem(2of2)

AU1310.0

Notes:
AIXfilestructure
Oneofthemajortasksofacomputersystemistoreadandwritedata.Inordertodo
this,AIXusesahierarchicalfiletreethatconsistsofdirectories,subdirectories,and
files.Thetopleveldirectoryiscalledtheroot( / )directorythathasmanysubdirectories.
Eachofthesesubdirectoriescancontainfilesorothersubdirectories.Adirectoryislike
afolderinwhichyouputcertaindocuments.

Filesystemtypes
Thefiletreeismountedduringthesystemstartup.AIXsupportsdifferentfilesystem
types,whichareallmountedtoonebigfiletree.Thisisshownonthevisual.Partsof
thisfiletreeresideonadisk,otherpartsmayresideonaCDROM,oraremounted
fromanothercomputerinanetwork.

16AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty Whatyouwilllearn
Thiscourseexplainshowtoworkwithdirectoriesandfilesonauserlevel.Youwilllearn
howtonavigateinthefiletreeandhowtomanagedirectories.Youwilllearnhowto
http://ss.hnu.cn/unix/ebook/aixbasics1.html

20/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

copy,move,deleteandprintfiles,andhowtoeditfilesusingv
i,whichisthecommon
UNIXeditor.Anothertopicwillshowhowtospecifycorrectfilepermissions.

CopyrightIBMCorp.1995,2008

Unit1.IntroductiontoAIX

17

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Activity:FillintheBlanks

K______

Interfaceto
hardware

S_____

User's
interface

http://ss.hnu.cn/unix/ebook/aixbasics1.html

21/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

F___
S______

Accessto
data

CopyrightIBMCorporation2008

Figure15.Activity:FillintheBlanks

AU1310.0

Notes:
Operatingsystemcomponents
Itisveryimportantthatyoubeabletoidentifythemostimportantcomponentsofan
operatingsystem.
Thisvisualintroducesthesecomponents,butasyounotice,thevisualisnotcomplete.
Takesometimeandtrytofillinthemissingwords.

18AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

TheShell:UserInterfacetoAIX
Executesusercommands:
Commandinterpreter
Features:
Wildcards
Variables

Customizable

Programming
language

Shell

Processcontrol

CopyrightIBMCorporation2008

Figure16.TheShell:UserInterfacetoAIX

http://ss.hnu.cn/unix/ebook/aixbasics1.html

AU1310.0

22/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Notes:
Introduction
WhenyouloginsuccessfullytoanAIXsystem,aspecialprogramisstartedforyou:the
shell.

Theshell
Theshellwaitsforinputandexecutesthecommandsandprogramsyoutypein.In
otherwordstheshellisacommandinterpreter.
Theshelloffersmanyfeatures(likewildcardstomatchfilenames,variables,command
lineediting)thathelptheuserinhisdailywork.Wewilldiscussallthesefeaturesinthis
course.
Theshelloffersdifferentwaystocontrolprocesses.Inthiscourse,weexplainhowa
usercancontrolhisprocesses.

CopyrightIBMCorp.1995,2008

Unit1.IntroductiontoAIX

19

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Customization
Theshelliscustomizable . Thatmeanstheuserinterfacemaybetailoredaccordingto
therequirementsofeachuser.Customizingtheuserenvironmentisanothertopicin
thiscourse.
Besidesalltheseproperties,theshellisaprogramminglanguage.Youcanwriteshell
scriptstocreateandtailorcommands.Writingsimpleshellscriptswillbecoveredlater
inthiscourse.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

23/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

110AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

UsefulAIXUtilities

Searchforspecificfiles

Searchforpatternsinfiles

file1

Comparefilesand
directories

Compressfiles

CopyrightIBMCorporation2008

Figure17.UsefulAIXUtilities

AU1310.0

Notes:
AIXutilities
TwocomponentsthatyouuseonAIXarefilesanddirectories.Toworkwiththese
components,AIXoffersawiderangeofutilities:
Thefindcommandtosearchforspecificfiles
Thegrepcommandtosearchforpatternsinfiles
Commandstocomparefilesanddirectories
Commandstocompressanduncompressfilestosavediskspace
Note thatthislistisnotcomplete.Besidestheseutilities,thecourseintroduces
additionaltoolsthatareusefulforyourwork.

CopyrightIBMCorp.1995,2008

Unit1.IntroductiontoAIX

111

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

24/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

StudentNotebook

AIXGraphicalUserInterfaces

Windows

Mouse
Pointer

Icons

CommonDesktop
Environment(CDE)

AIXWindows
CopyrightIBMCorporation2008

Figure18.AIXGraphicalUserInterfaces

AU1310.0

Notes:
Graphicaluserinterfaces
Modernoperatingsystemsarebasedongraphicaldesktops.Thesedesktopsconsistof
multiplewindowswhereyoucanstartdifferentapplications,iconsthatareminimized
windowstomanagethescreenspace,andfurthercontrols.
Toexecutecertainactionsonthedesktop,youhavetousethemouseattachedtothe
system.
AIXofferstwodifferentgraphicaluserinterfaces:
AIXwindows
CommonDesktopEnvironment(CDE)
Informationonusingandcustomizingthesedesktopsisincludedintheappendixofthis
course.

112AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty Additionaluserinterfaces
InAIX5L,ifyouaddtheAIXToolboxforLinuxApplications,youcaninstalltwoother
graphicaluserinterfaces:
KDE
http://ss.hnu.cn/unix/ebook/aixbasics1.html

25/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

GNOME

CopyrightIBMCorp.1995,2008

Unit1.IntroductiontoAIX

113

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Checkpoint
1. Whichpartoftheoperatingsysteminteractsdirectlywiththe
hardware?
2. Whichpartoftheoperatingsystemdoestheuserinteract
with?
a)Shell
b)Kernel

3. WhicheditorisavailableacrossmostUNIXplatforms?
http://ss.hnu.cn/unix/ebook/aixbasics1.html

26/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

4. WritedownthenamesoftwoAIXgraphicaluserinterfaces:
5. Trueorfalse:AIXonlysupportsfilesystemsonharddisks.

CopyrightIBMCorporation2008

Figure19.Checkpoint

AU1310.0

Notes:
Takesometimeandtrytoanswerthequestions.

114AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

UnitSummary
TheAIXKernelinterfacestohardwaredevicesandcontrols
processesrunningintheAIXsystem.
Theuser'sinterfacetoAIXistheshell.Theshellisacommand
interpreterthatoffersgreatflexibility.
TostoredataAIXusesahierarchicalfiletreethatconsistsof
directoriesandfiles.
AIXoffersawiderangeofusefulutilities.

CopyrightIBMCorporation2008

Figure110.UnitSummary

AU1310.0

Notes:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

27/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit1.IntroductiontoAIX

115

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

28/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

116AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Unit2.UsingtheSystem
WhatThisUnitIsAbout
ThisunitintroducesthestudentstoafewbasicAIXcommands.

WhatYouShouldBeAbletoDo
Aftercompletingthisunit,studentsshouldbeableto:
Loginandoutofthesystem
StatethestructureofAIXcommands
ExecutebasicAIXcommands
UseAIXcommandstocommunicatewithotherusers

HowYouWillCheckYourProgress
Accountability:
Checkpointquestions
Exercise

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

21

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

29/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

StudentNotebook

UnitObjectives
Aftercompletingthisunit,youshouldbeableto:
Loginandoutofthesystem
StatethestructureofAIXcommands
ExecutebasicAIXcommands
UseAIXcommandstocommunicatewithotherusers

CopyrightIBMCorporation2008

Figure21.UnitObjectives

AU1310.0

Notes:

22AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

LoggingInandOut

ToLogin:
login:team01

http://ss.hnu.cn/unix/ebook/aixbasics1.html

30/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

team01'sPassword:(thepassworddoesnotappear)
$

ToLogout:
(or)
(or)

$<Ctrld>
$exit
$logout
login:

CopyrightIBMCorporation2008

Figure22.LoggingInandOut

AU1310.0

Notes:
Introduction
BecauseAIXisdesignedasamultiusersystem,alevelofsecurityisimplementedto
controlaccess.Eachuserofthesystemhasausernameandassociatedpassword
(optional).

Username
Whenthesystemhasstartedandisreadyforausertologin,theloginprompt(typically
thewordlogin:)ispresentedonthescreen.Atthatpoint,theusershouldenterthe
suppliedusername.

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

23

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Userpassword
Iftheusernamerequiresapassword,thesystemwillpromptforthepasswordina
similarmanner.Whiletheuseristypingapassword,itdoesnotappearonthescreen.It
ishighlyrecommendedtousepasswordsonalluseraccounts.
Iftheuserpasswordwassetupbythesystemadministrator,thefirsttimethattheuser
logsintothesystem,theuserwillbepromptedtochangetheirpassword.

Successfullogin
Whenloggedin,theuserispresentedwithaprompt(normallyadollarsign)whichis
theshell'swayofrequestingacommand.

Exitingthesystem
Toterminatethesessiontheusermayeitherentertheexitorlogoutcommand,or
pressthekeycombination<Ctrl+d>(holdingdowntheCtrlkeywhilepressingthed
key).The<Ctrl+d>combinationgeneratestheendoffile(EOF)orendof
transmission(EOT)character.
http://ss.hnu.cn/unix/ebook/aixbasics1.html

31/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

logoutonlyworksifyouareinyourloginshell.
Whentheuserlogsout,afterafewsecondsanewloginpromptwillappearonthe
screen.

24AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Passwords

Creating or Changing :

$passwd
Changingpasswordfor"team01"
team01'sOldpassword:
team01'sNewpassword:
Enterthenewpasswordagain:
$

CopyrightIBMCorporation2008

Figure23.Passwords

AU1310.0

Notes:
Changingtheuserpassword
http://ss.hnu.cn/unix/ebook/aixbasics1.html

32/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

TheuserpasswordistheprimarymechanismforensuringsecurityonanAIXsystem.
Allpasswordsareencryptedandcannotbedecodedbyotherusers.
Thepasswdcommandisusedtochangetheuserpasswordandisanexampleofa
simplecommandwhichmaybeenteredattheshellprompt.
Thesystemwillstartthepasswdprocesswhichwillprompttheuserfortheirold
passwordfirst.Thecharacterstypedarenotdisplayedtothescreen.Topreventusers
beinglockedoutofthesystemthroughasimpletypingerror,thenewpasswordis
enteredtwice.Onlyifthetwoentriesmatchisthenewpasswordaccepted.Theold
passwordisinvalidthereafter.
Whenthepasswdprocessterminates,theuserisagainpresentedwiththeprompt
requestinganothercommand.

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

25

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

CommandFormat
AIXcommandshavethefollowingformat:
$commandoption(s)argument(s)
$ls
$lsl
$ls/dev
$lsl/dev

CopyrightIBMCorporation2008

Figure24.CommandFormat

AU1310.0

Notes:
Formattingacommand
Theorderandseparationoftheelementsofacommandareimportant.Thecommand
orprocessnamemustcomefirst.Spacesareusedbytheshellasseparatorsonthe
commandlineandshouldnotbeplacedwithinthecommandname.

Commandoptions
Theoptionsshouldfollowthecommandname,separatedbyaspace,andprecededby
aminussign( ).Usually,multipleoptionsmaybegroupedtogetherimmediatelyaftera
singleminussignorseparatedbyspacesandeachprecededbyaminussign.Options
aretypicallyusedtomodifytheoperationoftheprocess.
http://ss.hnu.cn/unix/ebook/aixbasics1.html

33/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

26AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty Commandarguments
Theargumentsfollowtheoptions,againseparatedbyspaces.Theorderofthe
argumentswilldependonthecommand.

Example
Allthreeelementsarenotrequiredtobepresentatalltimes,forexample:
$ls

justcommand

$lsl

commandandoption

$ls/tmp

commandandargument

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

27

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

34/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CommandFormatExamples
WRONG:

RIGHT:

1.Separation:

1.Separation:

$mailfnewmail

$mailfnewmail

$whou

$whou

2.Order:

2.Order:

$mailnewmailf

$mailfnewmail

$team01mail

$mailteam01

$uwho

$whou

3.MultipleOptions:

3.MultipleOptions:

$whomu

$whomu

$whomu

$whomu

4.MultipleArguments:

4.MultipleArguments:

$mailteam01team02

$mailteam01team02

THEREAREEXCEPTIONS!!
CopyrightIBMCorporation2008

Figure25.CommandFormatExamples

AU1310.0

Notes:
Introduction
Thecommandsinthevisualdisplaysomeexamplesofcorrectandincorrectcommand
formats.

Exceptions
AfewcommandsinAIXdonotadheretothecommoncommandformat.Commands
suchastar,date,andpsacceptargumentsthatdonotbeginwithaminussign().
ThisistoensurebackwardscompatibilitywitholderimplementationsofUNIX.
$tarcvf/dev/rmt0/home/team01/*
$psaux
$date+%D

28AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

The dateandcalCommands

Checkingthedate:
$date
WedNov1410:15:00GMT2007
$

http://ss.hnu.cn/unix/ebook/aixbasics1.html

35/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Lookingatamonth:
$cal12003

January2003
WedThuFriSat
1
2
3
4
8
9
10
11
15
16
17
18
22
23
24
25
29
30
31

SunMonTue
5
12
19
26

6
13
20
27

7
14
21
28

Lookingatayear:
$cal2007

CopyrightIBMCorporation2008

AU1310.0

Figure26.Thedate andcal Commands

Notes:
Introduction
Thevisualshowshowthedateandcalcommandscanbeexecuted.

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

29

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

The clear, echo,andbannerCommands

clear: Clearstheterminalscreen
$clear

echo: Writeswhatfollowstothescreen
$echoLunchisat12:00
Lunchisat12:00
$

banner: Writescharacterstringsinlargeletterstothescreen
$bannerHello

http://ss.hnu.cn/unix/ebook/aixbasics1.html

36/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorporation2008

AU1310.0

Figure27.Theclear ,echo ,andbanner Commands

Notes:
Morecommands
Thisvisualshowshowtheclear,echo,andbannercommandswork.
Note :Insteadofechoyoucanusetheprintcommand:
$printLunchisat12:00
Lunchisat12:00

210AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Activity:QuestionsandAnswers
1.What'swrongwiththefollowingcommands?
$dusk
$dfk
$duak
2.Whichcommand...
...changesyourpassword?
...clearsthescreen?
...printsoutthecurrentsystemdate?
...exitsthecurrentshell?
CopyrightIBMCorporation2008

Figure28.Activity:QuestionsandAnswers

AU1310.0

Notes:
Questions
Takesometimeandanswerthequestions.
http://ss.hnu.cn/unix/ebook/aixbasics1.html

37/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

211

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

The whoand fingerCommands

Findingwhoisonthesystem:
$who
root
team01

Sept414:29
Sept417:21

Findingwhoyouare:
$whoami
team01
$whoami
team01

lft0
pts/0

pts/0 Sept417:21

Displayinginformationabouttheuserscurrentlyloggedon:
$fingerteam02
Loginname:team02
Directory:/home/team02
/usr/bin/ksh
OnsinceMar0416:17:10ontty3
NoPlan.

Shell:

CopyrightIBMCorporation2008

Figure29.Thewho andfinger Commands

AU1310.0

Notes:
whocommand
Thewhocommandidentifiedwhoisloggedinandwheretheyhaveloggedinfrom.
Sometimesitisdesirabletoknowwhatterminalyouareworkingwith,whichcaneasily
beidentifiedwiththewhoamicommand.Thiswillproduceoutputsimilartothewho
commandbutonlyfromyourownloginsession.
Earlierintheunit,optionswereintroducedwiththewhocommand.Herearesomemore
detailsontheirfunctions:
u

displaystheusername,extendedworkstationname,logintime,lineactivity
andprocessIDofthecurrentuser.

displaysinformationaboutthecurrentterminalandthisisequivalenttothe
whoamicommand.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

38/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

212AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty fingercommand
Thefingercommandhasadefaultformatwhichdisplays:Fullusername,logintime,
user's$HOMEdirectoryanduser'sloginshell.
Youcanuseyourownusernamewiththefingercommandtofindoutinformation
aboutyourself.

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

213

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

39/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

SendingMail
$mailteam01
Subject:
Meeting
Therewillbeabriefannouncementmeetingtoday
inroom602atnoon.
<Ctrld>
Cc: <Enter>
$

$mailteam20@sys2
Subject:Don'tForget!
Don'tforgetaboutthemeetingtoday!
<Ctrld>
Cc: <Enter>
$

CopyrightIBMCorporation2008

Figure210.SendingMail

AU1310.0

Notes:
Introduction
Themailcommandisaninteractivecommandusedtosendandreceivemail
messages.

Sendingamessage
Tosendamessage,invokethecommandbypassingitvaliduserIDs.Ifmorethanone
nameisgiven,thenamesmustbeseparatedfromeachotherwithablankspace.
NextthepromptSubject:willautomaticallybedisplayed.Thesendershouldfillinthis
fieldwithonelineoftextwhichcloselydescribesthecontentsofthemailbody.Thisis
thelinewhichwillappearintherecipient'slistofincomingmail.
Afterthesubjectline,thenotebodyshouldthenbeentered,andoncecomplete,press
a<Ctrld>onthenextavailableblankline.
Note:Thismustbethefirstandonlycharacteronthatline.Thisistheendoffilemarker.
214AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

TheCc:prompt(denotingcarboncopy)willthenbedisplayed,whichcanbeleftblank,
orastringofuserIDscanbeentered.
Afterthelastprompt,theshellpromptshouldbedisplayed.

Sendingmailtoothersystems
Whensendingmailtoanotheruseronyoursamesystem,entermail<username>.To
sendmailtoauseronanothercomputersystem,itisnecessarytoindicatethename
(thehostname)ofthatcomputer.Forexample,
mail<username>@<hostname>
http://ss.hnu.cn/unix/ebook/aixbasics1.html

40/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

215

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

ReceivingMail
[YOUHAVENEWMAIL]
$mail
Mail [5.2UCB][AIX5.X]Type?forhelp
"/var/spool/mail/team01":2messages1new
U1team05

TueJan7 10:50

10/267"Hello!"

>N2team02

WedJan8 11:25

16/311"Meeting"

?t2
Fromteam02WedJan811:252003
Date:Wed8Jan200311:25
From:team02
To:team01
Subject:Meeting
Cc:
Therewillbeabriefannouncementmeetingtodayinroom602atnoon.
?d

(Deletemessage)
(Quitmailcommand)

http://ss.hnu.cn/unix/ebook/aixbasics1.html

41/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

?q
CopyrightIBMCorporation2008

Figure211.ReceivingMail

AU1310.0

Notes:
Introduction
Theuserisinformedthatnewmailitemshavearrivedwhenthe[YOUHAVENEWMAIL]
messageisdisplayed.Thismessagedoesnotgetautomaticallydisplayedassoonas
theincomingmailarrives.Theshelldoesacheckonallthemailboxesbydefaultonce
every600seconds.Ifitdetectsanewpieceofmail,thenitdisplaysthemessage(which
itselfcanbecustomizedbythesystemadministrator).

Receivingmail
Toreceivethemailitemsusethemailcommandwithoutanyoptions.Itwilllistheader
informationandaonelinedescriptionforeachunreaditemfollowedbytheprompt?.
Thisisdifferentfromtheshellprompt.AIXusesthe?asthemailsubsystemprompt.

216AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Controllingthemailsubsystem
Atthisprompt,theusermayenteranyofthemailsubsystemcommands.Toobtaina
listentera?attheprompt.Normaloperationslikesaving,deleting,viewing,andso
forth,canbecarriedoutoneachmailitem.
Someofthecommandsthatcanbeusedatthe?promptare:
d
deletemessages
m
forwardmessages
R
sendreplytosenderofmessagesinthequeue
q
exitmailandleavemessagesinthequeue
s
appendmessagestoafile
t
displayamessage
x
exitmailanddiscardallchangestothequeue
Certainsubcommandslike dand tacceptmessagenumbersasarguments.They
defaulttothecurrentmessageifnoneisspecified.
Therearemanymore.Toobtainathelistofcommandsavailabletypeina?atthe?
promptorseetheAIX6.1CommandsReferenceManual.

Leavingthemailsubsystem
Havingfinishedworkingwiththemailitems,toreturntotheshellprompt,youmust
enteraq(forquit)atthe?prompt.Thiswilltakeyououtofthemailsubsystem.
Ifyouwishtoquitthemailsubsystemanddiscardanychangestothequeue,enteranX
(forexit)attheprompt.Messagesthatweremarkedfordeletionarenotdeleted.
Anysavedmailitemswhichhavebeenreadbutnotdeletedcannotbeviewedagain
usingtheabovemethod.Oncethemailitemisread,itwillbestoredinafileinthe
user'shomedirectorycalled$HOME/mbox.
Toviewtheseitemsyoumustusethemailfcommand.Thiswilllookatyourdefault
mailbox.Ifyouhavecreatedothermailboxes,thenyouhavetoalsospecifythemailbox
name.
http://ss.hnu.cn/unix/ebook/aixbasics1.html

42/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

217

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

The writeand wallCommands

Send messages tootherusers onasystem


writeprovides conversationlike communicationwithanotherloggedinuser.
Eachuseralternativelysendsandreceivesmessages.
$writeteam01

(or)

$writesarah@moon

Thewallcommandwritestoallterminals.Thisisusefultonotifyallusersofa
systemevent:
$wallThesystemwillbeinactivefrom10pmtoday.
Broadcastmessagefromteam01@sys1(pts/1)at15:11:58
Thesystemwillbeinactivefrom10pmtoday.
$
CopyrightIBMCorporation2008

Figure212.Thewrite andwall Commands

AU1310.0

Notes:
writeandwallcommands
Thewritecommandcanbeusedtosendmessagestousersonthissystemaswellas
usersofothersystemsconnectedtothenetwork.
Bothwriteandwallwillonlysendmessagestousersthatareloggedin.Bydefault,all
usershavetheabilitytoexecutethewallcommand.
writesendsmessagestoasingleuser.wallsendsmessagesalluserscurrently
loggedintothesystem.

Receivingmessages
Forausertoreceiveamessage,thatusermustbeloggedinandmustnothave
refusedpermission.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

43/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

218AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Writeexample
Toholdaconversationusingwriteenter:
$writesam
Press <enter>andtype:
Iwillneedtorebootthesystematnoon.<enter>
o<enter>
Thisstartstheconversation.Theoatthebeginningofthenextlinemeansthe
messageisoverandyouarewaitingforaresponse.Now,Samenters:
$writebill
Thankyouforlettingmeknow!<enter>
oo<enter>
Theoomeansoverandouttellingthesenderyouhavenothingmoretosay.Press
<Ctrl+d>toendthewritesession.

Sendingmessagestousersonothersystems
writecanalsobeusedacrossanetworkaslongasthewritesrvdaemonisrunning.
Tousewriteoverthenetworktypewrite<username>@<hostname>.

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

219

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

44/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

talkwithAnotherUser
$talkfred

(userjohnrequeststheconnection)

(toaccepttheinvitationfredenters:)

CopyrightIBMCorporation2008

AU1310.0

Figure213.talk withAnotherUser

Notes:
Twowaycommunication
Thetalkcommandallowstwouserstoholdaconversation.Oneuserinvitestheother
toholdaconversationbyissuingthetalkcommand.Thetalkcommandopensasend
windowandareceivewindowoneachuser'sdisplay.Eachuseristhenabletotypeinto
thesendwindowwhilethetalkcommanddisplayswhattheotheruseristyping.
Iftheinvitationisaccepted,eachuser'sscreenissplithorizontallyintotwowindows.In
thetopwindoweverythingtheotherusertypesisdisplayed.
Toclosetheconnection,presstheINTERRUPTkey<Ctrl+c>.
talkcanalsobeusedinanetwork.Totalktofred onsys1 ,thecommandwouldbe
talkfred@sys1.

220AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

mesg

The mesgcommandcontrolswhetherotherusersonthe
systemcansendmessagestoyou:
team01$mesg
Thecurrentstatusisy.
team01$mesgn
team01$

http://ss.hnu.cn/unix/ebook/aixbasics1.html

45/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

team02$writeteam01
write:0803031Permissiondenied.
team02$

CopyrightIBMCorporation2008

Figure214.mesg

AU1310.0
.

Notes:
Permittingmessages
Theshellstartupprocesspermitsmessagesbydefault.Thevisualshowshowthemesg
commandworkcanbeusedtoallowordenymessages.
Themesgcommanddetermineswhethermessagescanbesenttotheuserwitheither
thetalk,thewrite,orthewallcommands.
Permittingordenyingmessagescanalsobesetaspartofyoursessioncustomization
whichwewillcoverlaterinthiscourse.

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

221

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

KeyboardTips
<Backspace>

Correctsmistakes

<Ctrlc>

Terminatesthecurrent
commandandreturnstothe
shell

<Ctrld>

Endoftransmissionorend
offile

<Ctrls>

Temporarilystopsoutputto
thescreen

<Ctrlq>

Resumesoutput(stoppedby
Ctrls)

<Ctrlu>

Erasestheentireline
CopyrightIBMCorporation2008

http://ss.hnu.cn/unix/ebook/aixbasics1.html

46/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Figure215.KeyboardTips

AU1310.0

Notes:
Keyboardtips
Donotusethecursorkeystocorrectmistakes,suchastheupordownarrowkeyorthe
tabkeys.ThebestwaytocorrectmistakesistousetheBackspacekey.
The <Ctrls>and<Ctrlq>keysaresomewhatsystemdependent.OnsomeASCII
terminals,theHoldkeycanbeusedasatogglekeytostartandstopoutputtoyour
terminal.

222AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Checkpoint
1. WhatisthecorrectcommandsyntaxinAIX?
$mailnewmailf
$mailfnewmail
$fmail
$mailfnewmail

2. Whatcommandwouldyouusetosendmailitems?
3. Whatareothercommandsthatcanbeusedtocommunicatewith
otherusers?
4. Whatoutputwouldyouexpectfromthefollowingcommand:cal8?
5. Whichcommandwouldyouusetofindoutwhenaparticularuser
loggedin?
$whoami
$who
$fingereveryone
$fingerusername

CopyrightIBMCorporation2008

Figure216.Checkpoint

AU1310.0

Notes:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

47/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

223

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Exercise:UsingTheSystem

CopyrightIBMCorporation2008

Figure217.Exercise:UsingTheSystem

AU1310.0

Notes:
ExerciseIntroduction
Attheendofthelab,youshouldbeableto:
LogintoanAIXsystemandchangepasswords
Executebasiccommands
Usethewallandwritecommandstocommunicatewithotherusers
Usekeyboardcontrolkeystocontrolcommandlineoutput

224AIX6Basics

http://ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

48/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

UnitSummary
AIXcommandscanusemultipleoptionsandargumentsand
mustfollowpropersyntaxrules.
Therearemanysimple,yetpowerfulcommandssuchas:
date
cal
who,whoamI
finger
echo
clear
banner
CommunicatewithotherUNIXusersusingcommandssuch
as: mail, write, talk,andwall.
CopyrightIBMCorporation2008

Figure218.UnitSummary

AU1310.0

Notes:

CopyrightIBMCorp.1995,2008

Unit2.UsingtheSystem

225

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

49/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

226AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Unit3.AIX6.1Documentation
WhatThisUnitIsAbout
Thisunitillustratesthedifferentmethodsthatcanbeusedtoobtain
onlinehelp.

WhatYouShouldBeAbletoDo
Aftercompletingthisunit,studentsshouldbeableto:
UsethemancommandtoviewinformationaboutAIXcommands
DescribetheuseofAIX6.1Webbaseddocumentation
http://ss.hnu.cn/unix/ebook/aixbasics1.html

50/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

HowYouWillCheckYourProgress
Accountability:
Checkpointquestions
Exercise

CopyrightIBMCorp.1995,2008

Unit3.AIX6.1Documentation

31

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

UnitObjectives
Aftercompletingthisunit,youshouldbeableto:
UsethemancommandtoviewinformationaboutAIX
commands
DescribetheuseofAIX6.1Webbasedonlinedocumentation

CopyrightIBMCorporation2008

Figure31.UnitObjectives

http://ss.hnu.cn/unix/ebook/aixbasics1.html

AU1310.0

51/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Notes:

32AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

manCommand

The mancommandprovidesreferenceinformationoncommands ,
subroutines ,andfiles
Manualinformationconsistsof:
Purpose
Syntax
Description
Flags
Examples
Files
RelatedInformation

(onelinedescription)
(allvalidoptionsandarguments)
(verbosedescription)
(descriptionofallvalidoptions)
(commandexamples)
(associatedfilesanddirectories)
(additionalresourcesandinformation)

CopyrightIBMCorporation2008

AU1310.0

Figure32.man Command

Notes:
mancommandfeatures
Themancommandwilllookintheonlinemanualforinformationonthecommands,
subroutines,andfileswiththenametitle.Thisinformationwillbepresentedonthe
screenonepageatatimefortheusertobrowse.
Theinformationconsistsof:
Purpose
Syntax
http://ss.hnu.cn/unix/ebook/aixbasics1.html

Thetitleandaonelinedescriptionofthecommand
Alistofallvalidoptionsandarguments
52/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Description

Manypagesofinformationaboutthefunctionandusageofthe
commandwithexamples
Descriptionofavailableoptions
Samplesofhowtousethecommand
Anysystemfilesassociatedwiththecommand
Thenamesofanyrelatedcommands

Flags
Examples
Files
Related Info .

CopyrightIBMCorp.1995,2008

Unit3.AIX6.1Documentation

33

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

manExample

Pum
$
ra
pn
o
sw
eho
Identifiestheuserscurrentlyloggedin.
Syntax
who[a|bdhiImpquHT][File]
whoam{i|I}
Description
Thewhocommanddisplaysinformationaboutalluserscurrentlyonthe
localsystem.Thefollowinginformationisdisplayed:loginname,
workstationname,dateandtimeoflogin.
Flags
m
uori

Displaysinformationaboutthecurrentterminal.The
whomcommandisequivalenttothewhoamiand
whoamIcommands.
Displaystheusername,workstationname,logintime,
lineactivity,andprocessIDofeachcurrentuser.

Examples
1.Todisplayinformationaboutwhoisusingthelocalsystemnode,
enter:
who
ImplementationSpecifics
ThiscommandispartofAsynchronousTerminalEmulation(ATE)
Files
/etc/utmp

Containsuserandaccountinginformation.

AU1310.0

Figure33.man Example

Notes:
Thisexampleshowsthe manwhocommand.Notethatthisexamplehasbeen
condensedtofitononepage.

34AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

53/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

V3.1
StudentNotebook

Uempty

mank:WorkingwithaKeyword
The koptionofthe mancommandallowsyoutoprintoutoneline
descriptionsofallentrieswhichmatchthegivenkeyword
Example:

$mankprint
cancel(1)
Cancelsrequeststoalineprinter
disable(1)Disablesaprinterqueuedevice
enable(1)
Enablesaprinterqueuedevice
lpr(1)
Enqueuesprintjobs
lpstat(1)
Displayslineprinterstatusinformation
qcan(1)
Cancelsaprintjob
qchk(1)
Displaysthestatusofaprintqueue

CopyrightIBMCorporation2008

AU1310.0

Figure34.mank :WorkingwithaKeyword

Notes:
Enablingthekfeature
Tousethekflag,asuperusermusthavetypedcatmanwtocreatethe
/usr/share/man/whatis file.

mankcommand
Themankcommandshowsthemanualsectionsthatcontainanyofthegiven
keywordsintheirpurposesection.Theoutputfromthecommandbeginswiththename
ofacommandandthesectionnumberinwhichthecommandappears.
Ifyouwanttoviewtheoutputfromthecommandenable(1),thenyoucanenter
$manenabletoobtainthemanualpagesfortheenablecommand.Ifthesection
numberisomitted,themancommandsearchesallthesectionsofthemanual.
Toobtainfurtherinformationaboutthevariousmansectionsentermanman.Notethat
theaproposcommandisequivalenttomank.
CopyrightIBMCorp.1995,2008

Unit3.AIX6.1Documentation

35

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

ViewingAIX6.1Documentation
DocumentationServer
http://ss.hnu.cn/unix/ebook/aixbasics1.html

54/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

AIX6.1softcopydocumentation
AIXInformationCenter
Webbrowsersoftware

DocumentationClient
Webbrowser
software

DocumentationClient
Webbrowser
software

ViewAIX6.1documentation
fromanywherewithabrowser
http://publib.boulder.ibm.com/infocenter/pseries
/v6r1/index.jsp
CopyrightIBMCorporation2008

Figure35.ViewingAIX6.1Documentation

AU1310.0

Notes:
Documentationserver
Inadditiontoprovidingmancommandstomakefindinginformationeasy,AIXalso
providessystemmanuals.ThedocumentsareavailableontheInternetattheIBMWeb
sitehttp://publib.boulder.ibm.com/infocenter/pseries/v6r1/index.jsp.Forsiteswithout
accesstotheInternet,softcopydocumentationcanbeloadedonadocumentation
serverwithinaprivatenetwork.AnyothercomputerinthenetworkwithWebbrowser
softwarecanthenbecomeadocumentationclientandaccessthesedocumentsfrom
theserver.

Requestsfordocuments
WhenusersonaclientcomputerrequestanAIXdocument,therequestissenttothe
Webserveronadocumentationserverwhichthensendsbacktherequesteditem.
Whensearchesareperformed,theyaredoneontheservercomputerandtheresults
arethensentbacktotheuserontheclientcomputer.
36AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

AccessingtheDocumentsfromaWebBrowser
MozillaFirefoxforAIX
Newfeatures,supportsmanycurrentWebstandards
64bit
AvailableasaWebdownloadoronCDwhenorderingAIX
(MozillaFirefoxforAIXCD)

Mozilla
StandardbrowserbeginningwithAIX5L5.3
SupportsallversionsofAIX5L
32bit
AvailableasaWebdownload
http://ss.hnu.cn/unix/ebook/aixbasics1.html

55/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

http://www.ibm.com/servers/aix/browsers

CopyrightIBMCorporation2008

Figure36.AccessingtheDocumentsfromaWebBrowser

AU1310.0

Notes:
WebBrowser
MozillaFirefoxforAIXisanopensourceWebbrowser.Itdelivershelpfulnewfeatures
andcontinuestoleadthewayinonlinesecurity.Itimplementstechnologieslikethe
Geckolayoutengine,andsupportsWebstandardsordraftstandardslikeHTML,
XHTML,XML,CSS,DOM,andmanymore.MozillaFirefoxforAIXimplementsOJI,the
OpenJavaInterfacetoAIXJavathroughtheAIXJavaPlugin.
MozillaFirefoxversion(64bit)isavailableasaWebdownloadandontheMozilla
FirefoxforAIXCDthatcanbeorderedwithAIX6.1.
TheMozillaWebbrowserwasintroducedwithAIX5LV5.2,andbecamethestandard
WebbrowserinAIX5LV5.3.ItisavailableasWebdownload.

CopyrightIBMCorp.1995,2008

Unit3.AIX6.1Documentation

37

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

AIX6.1Documentation

CopyrightIBMCorporation2008

Figure37.AIX6.1Documentation

AU1310.0

Notes:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

56/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Accessingdocumentation
Oncethedocumentationissetup,itcanbeaccessedfromtheAIXWindowsorCDE
environmentwiththeinfocentercommand.

Webaccess
Ifthedocumentationwasnotinstalledonyoursystem,itcanalsobeaccessedat:
http://publib.boulder.ibm.com/infocenter/pseries/v6r1/index.jsp

Viewingdocuments
Thedocumentscanbeviewedtwoways.Eitherbyselectingtheentiredocumentwith
thePDFtagattheendofeachdocumentnameorbyselectingtheHTMLtagand
viewingthedocumentsectionbysection.
38AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty Searching
InthetopleftcorneroftheInformationCenterpage,thereisaboxforenteringsearch
strings.EnteringinformationandselectingGOwillsearchalldocumentsforthestring.
YoucanselectSearchScopetolimitthesearchtoasetofdocuments.

Printingdocuments
TheInformationCenterallowsyoutoprintdocumentsintwoways.
YoucandownloadthePDFdocumentandprinttheentiredocumentfromAdobe
Acrobat.
OraccessasectionofadocumentinHTMLandprintthatsectionasyouwould
normallyprintthecontentsofaWebpage.Findthesectionyouwishtoprintanduse
thebrowsersPrintfunctionusuallyfoundintheFilemenu.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

57/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit3.AIX6.1Documentation

39

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

SearchAIX6.1Documentation

CopyrightIBMCorporation2008

Figure38.SearchAIX6.1Documentation

AU1310.0

Notes:
Searchingdocuments
Probablytheeasiestwaytofindanansweristosearchthedocumentationusingthe
SearchwindowontheInformationCenterscreen.
Abovearetheresultsofasearch.Intherightframearethematchesfromthesearchin
orderofqualitywiththebestmatchatthetopofthelist.

310AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

58/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

V3.1
StudentNotebook

Uempty

SearchScope

CopyrightIBMCorporation2008

Figure39.SearchScope

AU1310.0

Notes:
SearchScope
ByselectingtheSearchScopelink,youcannarrowthesearchtoasubsetof
documents.

CopyrightIBMCorp.1995,2008

Unit3.AIX6.1Documentation

311

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Checkpoint
1. Whichcommanddisplaysmanualentriesonline?
2. Completethefollowingsentences:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

59/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

TheAIX6.1onlinedocumentationisloadedona
________________.Anyothercomputerinthenetwork
withappropriateWebbrowsersoftwarecanthenbecomea
_______________.
3. Howcanyoustartthedocumentationfromthecommand
line?

CopyrightIBMCorporation2008

Figure310.Checkpoint

AU1310.0

Notes:

312AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Exercise:AIX6.1Documentation

http://ss.hnu.cn/unix/ebook/aixbasics1.html

60/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorporation2008

Figure311.Exercise:AIX6.1Documentation

AU1310.0

Notes:
Aftercompletingthelabexercise,youwillbeableto:
Executethemancommand
InitiateMozillatoaccessAIXonlinedocumentation
UsetheAIXdocumentation

CopyrightIBMCorp.1995,2008

Unit3.AIX6.1Documentation

313

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

UnitSummary
The mancommandcanbeusedfromthecommandlineto
viewdescriptionsofAIXcommands.
UseaWebbrowser toaccessonlinedocumentation with
AIX6.1.
TheonlinedocumentationandSystempInfoCenterusethe
sameinterface .

CopyrightIBMCorporation2008

Figure312.UnitSummary

AU1310.0

Notes:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

61/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

314AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Unit4.FilesandDirectories
WhatThisUnitIsAbout
Thisunitintroducesbasicconceptsforfilesanddirectories.

WhatYouShouldBeAbletoDo
Aftercompletingthisunit,studentsshouldbeableto:
Describethedifferentfiletypes
DescribetheAIXfilesystemstructure
Usebothfullandrelativepathnamesinafilespecification
Create,delete,andlistdirectories
Usethetouchcommandtocreateanemptyfile

HowYouWillCheckYourProgress
Accountability:
StudentActivity
Checkpointquestions
Exercise

http://ss.hnu.cn/unix/ebook/aixbasics1.html

62/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

41

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

UnitObjectives
Aftercompletingthisunit,youshouldbeableto:
Describethedifferentfiletypes
DescribetheAIXfilesystemstructure
Use full and relativepathnames inafilespecification
Create,delete,andlistdirectories
Usethetouchcommandtocreateanemptyfile

CopyrightIBMCorporation2008

Figure41.UnitObjectives

AU1310.0

Notes:

42AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

63/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Uempty

AFile
Afileis:
Acollectionofdata
Astreamofcharacters ora"bytestream"
Nostructure isimposedonafilebytheoperatingsystem

CopyrightIBMCorporation2008

Figure42.AFile

AU1310.0

Notes:
Introduction
AIXimposesnointernalstructureonafile'scontent.Theuserisfreetostructureand
interpretthecontentsofafileinwhateverwayisappropriate.

CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

43

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

FileTypes

Ordinary:
Text or codedata

http://ss.hnu.cn/unix/ebook/aixbasics1.html

64/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Directory:
A tableofcontents,thatstoresalistoffiles withinthat
directory

SpecialFiles:
Representhardwareorlogicaldevices
Example:TheCDROM deviceisaccessedviathe/dev/cd0file.
CopyrightIBMCorporation2008

Figure43.FileTypes

AU1310.0

Notes:
Variousfiletypes
Mostordinaryfilesarecomprisedofalphanumericcharactersandpunctuationcodedin
ASCIIandcanbeviewed,edited,andprintedusingcommontools.
Someordinaryfileshavedatacodedinaformatthatisuniquetoanapplicationand
specialtoolsareneeded.Forexample,thefile/etc/utmp ,whichcontainsalistof
currentlyloggedinusers,canonlybereadbythewho command.
Otherfilescontaincodethatcanbeexecutedbyusersonthecomputer.Thesefilesare
knownasbinaryfiles.TheseprogramsaretreatedbyAIXasordinaryfiles.
Directoriescontainalistoffileswithinthatdirectory,andtheinformationthesystem
needstoaccessthefiledata.Eachdirectoryentryrepresentseitherafileoranother
directory,knownasasubdirectory.

44AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Specialfilesbehavedifferentlyfromordinaryfilesinthatthedatawrittentothefileis
processedbyadevicedriverandtypicallysenttothatdevice,suchasaprinter,rather
thanbeingstoredinthefile.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

65/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

45

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

DirectoryContents
inodeTable

Directory
name

inode

type mode links

subdir1

dir

755

myfile

10

10

file

644

user

group

date

team01

staff

team01

staff

July10
10:15
July11
11:00

size loc
512
96

Data

$vimyfile

CopyrightIBMCorporation2008

Figure44.DirectoryContents

AU1310.0

Notes:
Introduction
Directoriesenableyoutogrouptogetherrelatedfilesanddirectories.Adirectoryisa
http://ss.hnu.cn/unix/ebook/aixbasics1.html

66/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

uniquetypeoffilethatonlycontainsenoughinformationtorelateafilenametothe
inodewhichanchorsanddescribesthefile.Asaresult,directoriesusuallyoccupyless
spacethanordinaryfiles.

Directorycontents
Eachdirectoryentrycontainsafileorsubdirectorynameanditsassociatedindexnode
(orinode)number.

Useraccesstofiles
Whenauserexecutesacommandtoaccessafile,theywillusethefilename.The
systemthenmatchesthefilenamewiththecorrespondinginodenumber.Oncethe
46AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

inodenumberisknown,thesystemwillaccessaninodetable,whichholds
informationaboutthecharacteristicsofthefile.

inodeinformation
ExamplesofwhatisstoredintheinodetableincludetheuserIDoftheownerofthe
file,thetypeoffile,thedatethefilewaslastaccessedandlastmodified,thesizeofthe
file,andthelocationofthefile.Oncethesystemknowsthelocationofthefile,the
actualdatacanbelocated.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

67/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

47

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

AIXFileSystems
Referstoboththephysicalandlogicalstorageandaccessof
files.
InAIX,afilesystem isanallocationofstorage.
SimilarinconcepttopartitionsinthePCenvironment.
Allowstheoperatingsystemtostoreandretrievethedata
fromfilesquicklyandefficiently.
Toaccessfilesystems,weassociatethemwithadirectory .
AIXhasseveralpredefinedfilesystems:
/(root)
/usr
/var
/proc

/tmp
/opt
/home

CopyrightIBMCorporation2008

Figure45.AIXFileSystems

AU1310.0

Notes:
Physicalfilesystems
Thetermfilesystemreferstoboththephysicalstorageofthefiledata,andthelogical
organizationofdirectoriestoallowquickandeasystorageandretrievalofthatdata.
Aphysicalfilesystemisanallocationofstorage,onadevicesuchasaharddiskora
CDROMdrive.Theconceptisverysimilartopartitionsonsomeoperatingsystems.
Spaceisassignedonadevice,andassociatedwithanidentifierthattheusercan
access.InAIX,thisidentifierisadirectoryinthesystemwidelogicalfilesystem
structure.
Ifaphysicalfilesystemfillsup,thennomorefilescanbecreatedwithinthesystem.
TheslideliststhepredefinedAIXphysicalfilesystems.

48AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

68/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Uempty

HierarchicalStructure
/

usr

dev

etc

sbin

home

var

tmp

opt

proc

tty1
lp0

bin

team01

test

doc

.profile
manuals
test1

team02

team03

c
mon_report
trio_ltr
walrus

reports

pgms
suba

CopyrightIBMCorporation2008

Figure46.HierarchicalStructure

AU1310.0

Notes:
AIXfilesystem
ThisfilestructurerepresentsonlypartofatypicalAIXfilesystem.Thefilestructurewill
alwaysstartatthe/(root) directory.Itcontainsmanydirectoriesthatarecriticalinthe
operationsofthesystem.

Examples
SomeofthetypicaldirectoriesthatcanbefoundinanAIXroot directoryare:
/sbin Utilitiesforsystemstartup
/dev Specialfilesthatrepresentdevices
/etc Systemconfigurationfiles
The/usr directorycontainsprograms,libraries,anddatafilesforvariousAIX
applications:
CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

49

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

The/home directorycontainsuserlogindirectoriesandfiles.
The/var directorycontainsfilesthatdynamicallychange.
The/tmp directorywillholdfilescreatedbyexecutingprograms.
The/opt directoryiswherethirdpartyapplicationprogramscanbestored.Anexample
offilesinthisdirectoryarethebasicLinuxcommands,suchastar,gzip,gunzip,
bzip2,andsoforth,whichareinstalledinthe /opt/freeware/bin directory.
The/proc directoryiswhereAIXmapsprocessesandkerneldatastructuresto
correspondingfiles.

Accessingdirectoriesonothersystems
http://ss.hnu.cn/unix/ebook/aixbasics1.html

69/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Itisalsopossibletoaccessfilesonanothercomputerinthenetwork.Severalfacilities
areavailabletodothis,mostnotably,theNetworkFileSystem(NFS).Fromauser's
perspective,remotefileswillappeartobehavejustlikelocalfiles.

410AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

PathNames

A sequenceofnames ,separatedbyslashes(/),thatdescribesthe
path thesystemmustfollow to locate afileinthefilesystem.
Therearetwotypesofpathnames:
AbsoluteorFullPathName(startfromthe/directory):
$vi/home/team01/doc/mon_report
$/usr/bin/lsl/home/team01

RelativePathName(startfromcurrentdirectory):
$cd/home/team01
$vidoc/mon_report
$cd/usr/bin

http://ss.hnu.cn/unix/ebook/aixbasics1.html

70/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

$./lsl/home/team01
CopyrightIBMCorporation2008

Figure47.PathNames

AU1310.0

Notes:
Filepathnames
Thepathnameiswrittenasastringofnamesseparatedbyforwardslashes( / ).The
rightmostnameisthefileyouwishtoaccess.Theothernamesarethedirectoriesand
subdirectoriesthatdescribehowtogettothefileslocation.
Apathnameisalwaysconsideredtoberelative unlessitbeginswithaslash.An
absolute orfull pathnamealwaysstartswithaslash.

CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

411

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

WhereAmI?

The printworkingdirectory commandcanbeusedtofindoutwhat


yourcurrentdirectoryis:

$pwd
/home/team01

CopyrightIBMCorporation2008

Figure48.WhereAmI?

AU1310.0

Notes:
Usingthepwdcommand
Thepwdcommandwillalwaysreturnthefullpathnameofyour(current)present
workingdirectory.Itisnotabadideatousethiscommandoften,especiallywhenyou
areremovingfiles(tobesurethatyouareremovingthemfromthecorrectdirectory).
http://ss.hnu.cn/unix/ebook/aixbasics1.html

71/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

412AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

ListingDirectories
Syntax:ls [directory]
Commonoptions:
a:Showhiddenfiles(filesthatstartwitha.)
R:Listfilesinallsubdirectories(recursively)
$ls
cdocmanualstest1
$lsa
.profilecdocmanualstest1
$lsR
cdocmanualstest1
./c:
./doc:
Mon_reporttrio_ltrwalrus

CopyrightIBMCorporation2008

Figure49.ListingDirectories

AU1310.0

Notes:
Executingthelscommand
Thelscommandisusedtolistthecontentsofadirectory,andhasmanyusefuloptions
withit.Ifnofileordirectorynameisspecifiedasanargumenttothelscommand,the
currentdirectorywillbeused.
Bydefault,thelscommanddisplaystheinformationinalphabeticorder.Whenthels
commandisexecuteditdoesnotdisplayanyfilenamesthatbeginwithadot( .),unless
theaoptionisused(ascanbeseenonthevisual).Thesefilesaregenerallyreferred
toashiddenfiles,forthisreason.
Tolistallthesubdirectoriesandtheircontents,theRoptioncanbeused.Thisisalso
knownasarecursivedirectorylisting.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

72/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

413

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

LongListingofFiles
The lscommandwiththe loptioncanbeusedtoobtain
moreinformationaboutthefilesinadirectory.
$lsl
total5
drwxrwxrx
drwxrwxrx
rwxrwxrx
rwxrwxrx

2
2
1
2

team01staff
team01staff
team01staff
team01staff

$lslitest1
29rwxrwxrx2team01staff

1024Aug12
512 Feb18
320 Feb22
144 Feb22

10:16c
09:55doc
07:30suba
16:30test1

144

16:30test1

Feb22

CopyrightIBMCorporation2008

Figure410.LongListingofFiles

AU1310.0

Notes:
Filelistingdetails
Thefieldsfromthelslcommandareasfollows:
Permission
bits

Link

Owner

Group

Size

Mtime

drwxrwxrx

team01

staff

1024

Aug12

10:16

drwxrwxrx

team01

staff

512

Feb18

09:55

doc

rwxrwxrx

team01

staff

320

Feb22

07:30

suba

rwxrwxrx

team01

staff

144

Feb22

16:30

test1

Name

Field1showsthefiletype(suchasordinaryordirectory)andthepermissionbits.File
anddirectorypermissionswillbecoveredinmoredetailinalaterunit.
Field2isthelinkcount.Linkswillbecoveredinmoredetailinthenextunit.

414AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Field3showstheusernameofthepersonwhoownsthefile.
Field4showsnameofthegroupforwhichgroupaccessprivilegesareineffect.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

73/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Field5showsthecharactercountoftheentry.
Field6showsthedatethecontentsofthefileordirectorywerelastmodified.
Field7showsthenameofthefile/directory.
Theioptionusedwiththelscommanddisplaystheinodenumberinthefirst
column.
Thelscommandismerelydisplayingfileanddirectoryinformationfromtheinode
table.Onlythelastcolumn,thename,comesfromthedirectoryitself.
Notethesizeofthedirectoriesintheaboveexample.Directoryspaceisallocatedin
512byteincrementsandgrowsin512byteincrements.

CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

415

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

ChangeCurrentDirectory
Syntax:cd[directory]
Setthecurrentworkingdirectoryfrom/home/team01 to
/home/team01/doc:
$cddoc
$cd/home/team01/doc
http://ss.hnu.cn/unix/ebook/aixbasics1.html

relativepath
fullpath
74/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Setyourworkingdirectorytoyourhomedirectory:
$cd

Setyourworkingdirectorytotheparentdirectory:
$cd..

CopyrightIBMCorporation2008

Figure411.ChangeCurrentDirectory

AU1310.0

Notes:
Introduction
Thecdcommandisusedtochangeyourcurrentworkingdirectory.

Returningtothehomedirectory
Usingthecdcommandwithnothingafteritwillautomaticallyreturnyoutoyourhome
directory.Thisisthedirectoryintowhichyouareusuallyplacedwhenyoulogin.

416AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Activity:Q+A
1.Howcanyoudeterminetheinodenumber ofafile?
2.Wherearethenames and inodenumbers offilesstored?
3.Howcanyoudetermineyourcurrentdirectory ?
4.Howcanyoulistallfilesinadirectory ,includinghiddenfiles ?
5.Yourcurrentdirectoryis/usr/dt/bin.Whatistheeasiestwaytochangeto
your homedirectory ?
6.Whichfilenamesarerelative(checkallthatapply)?

../team03/dir1

/tmp/file1

/.profile

./.profile
7.Writedownthethreedifferentfiletypes thatAIXknows:
1.
2.
3.
CopyrightIBMCorporation2008

http://ss.hnu.cn/unix/ebook/aixbasics1.html

75/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
Figure412.Activity:Q+A

AU1310.0

Notes:
Takesometimeandanswerthequestions.
Yourinstructorwillreviewthequestionswithyouafterwards.

CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

417

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

CreatingDirectories
Syntax:mkdirdirectory
Tocreatethedirectorytest ,asasubdirectoryof/home/team01:
$mkdir/home/team01/test

fullpathname

(or)
$cd/home/team01
$mkdirtest

relativepathname

CopyrightIBMCorporation2008

Figure413.CreatingDirectories

AU1310.0

Notes:
mkdircommand
Themkdircommandcreatesoneormorenewdirectoriesspecifiedbythedir_name
parameter.Eachnewdirectorycontainsthestandardentries.(dot)and..(dotdot).
Themoptioncanbeusedwiththemkdircommandtospecifythedirectorybeing
createdwithaparticularsetofpermissions.PermissionswillbecoveredinUnit6.
http://ss.hnu.cn/unix/ebook/aixbasics1.html

76/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

418AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

RemovingDirectories
Syntax:rmdirdirectory
Removethedirectory/home/team01/test:
$rmdir/home/team01/test

Thedirectorymustbeempty!
$rmdirdoc
rmdir:Directorydocisnotempty.

CopyrightIBMCorporation2008

Figure414.RemovingDirectories

AU1310.0

Notes:
Removingdirectories
Yougetnomessageifthecommandissuccessful.Itneverhurtstofollowacommand
suchasthiswithanls,whichisdiscussedonthenextpage,tomakesurethatyou
haveaccomplishedwhatyousetouttodo.
Adirectoryisconsideredemptyifitcontainsonlythe. and.. entries.

CopyrightIBMCorp.1995,2008

http://ss.hnu.cn/unix/ebook/aixbasics1.html

Unit4.FilesandDirectories

419

77/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

WorkingwithMultipleDirectories

Createmultipledirectoriessimultaneously:
$mkdirpdir1/dir2/dir3

/
home

team01

home

dir1
dir2

team01

dir3

Removealldirectoriesinthepathspecified:
$rmdirpdir1/dir2/dir3
CopyrightIBMCorporation2008

Figure415.WorkingwithMultipleDirectories

AU1310.0

Notes:
Multipledirectories
Usingthepoptionwiththemkdircommandallowsyoutocreatemultiple
subdirectoriessimultaneously.Ifdir1 anddir2 alreadyexist,thendir3 willbecreated.
Thepoptionusedwithrmdirfirstremovesthedir3 directory,thenthedir2 directory,
andfinallythedir1 directory.Ifadirectoryisnotemptyoryoudonothavewrite
permissiontoitwhenitisremoved,thecommandterminateswithanerror.

420AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

DisplayingDirectoryInformation
http://ss.hnu.cn/unix/ebook/aixbasics1.html

78/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

$lsldimydir
51drwxrxrx2team01staff

512Jan1717:38mydir

$istatmydir
Inode51ondevice10/8Directory
Protection:rwxrxrx
Owner:208(team01)Group:1(staff)
Linkcount:2
Length512bytes
Lastupdated:
Lastmodified:
Lastaccessed:

ThuJan
ThuJan
FriJan

17
17
18

21:05:43 2002
17:38:52 2002
13:30:00 2002

CopyrightIBMCorporation2008

Figure416.DisplayingDirectoryInformation

AU1310.0

Notes:
Usingtheistatcommandtoqueryinodes
Theioptiondisplaystheinodenumberinthefirstcolumn.Thedoptionusedwithls
willlisttheinodeinformationforadirectory.
Thelscommandhasoptionsthatcandisplayeachofthetimestamps:
Todisplaytheupdatedtime(utime):lslc
Todisplaythemodificationtime(mtime):lsl
Todisplaytheaccesstime(atime):lslu
istatdisplaystheinodeinformationforaparticularfileordirectory.AIXsystems
maintainthreetimestampsforfilesanddirectories.Theupdatedtimereflectschanges
donetotheinodeinformationwhereas,themodificationtimereflectschangestothe
contentsofthefileordirectoryitself.Theaccesstimeisthelasttimethefilewasreador
written.Readingafilechangesitsaccesstime,butnotitsupdatedtimeormodification
time,becauseinformationaboutthefileordirectorywasnotchanged.
CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

421

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

AIXFileNames
Shouldbedescriptive ofthecontent
Shoulduseonlyalphanumericcharacters :
UPPERCASE,lowercase,number,#,@,_

Shouldnotincludeimbeddedblanks
Shouldnotcontainshellmetacharacters :
*?></&![]|$\'"()

Should not beginwith" + "or" "sign


Should not bethesame asasystemcommand
Are casesensitive
http://ss.hnu.cn/unix/ebook/aixbasics1.html

79/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Filenamesstartingwitha . ( dot )arehiddenfromthenormalls


command
The maximumnumberofcharacters forafilenameis255

CopyrightIBMCorporation2008

Figure417.AIXFileNames

AU1310.0

Notes:
AIXfilenames
AIXhasnonotionoffilenameextensionsasyouhaveinotheroperatingsystems(such
asDOS).Thedotissimplyusedaspartofthefilename.Applicationsmayusethisto
describethecontentsofafile,butitisnotenforcedorrequiredbyAIX.

422AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

touchCommand
The touchcommandupdatestheaccess and modificationtimes ofa
file.Thecommandcanalsobeusedtocreatezerolengthfiles .

$lsl
rwxrwxrx

1team01staff

320Jan607:30suba

$date
TuesSep1012:25:002002
$touchsubanew_file
$lsl
rwxrwxrx 1team01staff
rwrr 1team01staff

320Sep1012:25suba
0Sep1012:25new_file

CopyrightIBMCorporation2008

Figure418.touch Command

http://ss.hnu.cn/unix/ebook/aixbasics1.html

AU1310.0

80/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Notes:
Creatingemptyfiles
Thetouchcommandservestwopurposes.Ifthefilespecifiedbythefilenamedoesnot
exist,azerolength(empty)fileiscreated.Ifthefiledoesexist,thelastmodification
time(displayedwithlsl)isupdatedtoreflectthecurrentdateandtime.
Ifyoudonotspecifyatimevariablewiththetouchcommandthecurrentdateandtime
willbeused.
touchcanalsobehelpfulwhenusedinsituationswhereanapplicationchecksafile's
lastmodificationtimebeforetakingsomeactionsuchasbackuporcompile.

CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

423

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Checkpoint(1of2)
1. Usingthetreestructureshownearlier,andusing/home as
yourcurrentdirectory,howwouldyourefertothesuba filein
the pgms directoryusingbothfullandrelativepathnames?

2. Whenspecifyingapathname,whatisthedifference
betweenthe.andthe..?
3. Whatwillthecd ../..commanddo?
4. Whatconditionshavetobesatisfiedinorderforthermdir
commandtocompletesuccessfully?

CopyrightIBMCorporation2008

Figure419.Checkpoint(1of2)

AU1310.0

Notes:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

81/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

424AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Checkpoint(2of2)
5. Matchthevariousoptionsofthelscommandwiththeir
functions.
a
i
d
l
R

__Providesalonglistingoffiles
__Listshiddenfiles
__Listssubdirectoriesandtheircontentsrecursively
__Displaystheinodenumber
__Displaysinformationaboutadirectory

6. Circlethefollowingvalidfilenamesinthefollowinglist:
1
aBcDe
myfile
my_file
my.file
myfile
.myfile

CopyrightIBMCorporation2008

Figure420.Checkpoint(2of2)

AU1310.0

Notes:

CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

425

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

82/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

StudentNotebook

Exercise:FilesandDirectories

CopyrightIBMCorporation2008

Figure421.Exercise:FilesandDirectories

AU1310.0

Notes:
Afterthisexercise,youwillbeableto:
Workwithdirectories
Usethelscommand
Usethetouchcommand

426AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

UnitSummary
Therearethreetypesoffileswhicharesupported:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

83/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Ordinary
Directory
Special

TheAIXfilesystemstructureisahierarchicaltree.
Filesareaccessedusingeitherfullorrelativepathnames.A
pathnamealwaysbeginswitha/(forwardslash).
Thefollowingcommandscanbeusedwithdirectories:
pwd, cd, mkdir, rmdir, and ls.

CopyrightIBMCorporation2008

Figure422.UnitSummary

AU1310.0

Notes:

CopyrightIBMCorp.1995,2008

Unit4.FilesandDirectories

427

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

84/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

428AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Unit5.UsingFiles
WhatThisUnitIsAbout
Thisunitintroducesusefulcommandstobeusedwhenworkingwith
AIXfiles.

WhatYouShouldBeAbletoDo
Aftercompletingthisunit,youshouldbeableto:
Usethecpcommandtocopyfiles
Usethemvcommandtomoveorrenamefiles
Usethewccommandtocountthenumberoflines,words,and
bytesinanamedfile
Usethelncommandtoallowafiletohavemorethanonename
Displaythecontentsofafileusingthecat,pg,andmore
commands
Usethermcommandtoremovefiles
Printfiles

HowYouWillCheckYourProgress
Accountability:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

85/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Studentactivity
Checkpointquestions
Exercise

CopyrightIBMCorp.1995,2008

Unit5.UsingFiles

51

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

UnitObjectives
Aftercompletingthisunit,youshouldbeableto:
Usethecpcommandtocopyfiles
Usethemvcommandtomoveorrenamefiles
Usethewccommandtocountthenumberoflines,words,and
bytesinanamedfile
Usethelncommandtoallowafiletohavemorethanone
name
Displaythecontentsofafileusingthecat, pg,andmore
commands
Usethermcommandtoremovefiles
Printfiles

CopyrightIBMCorporation2008

Figure51.UnitObjectives

AU1310.0

Notes:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

86/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

52AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

CopyingFiles
cpsourcetarget
cpfile1file2...target_dir
Tocopythefile/home/team03/pgms/suba to /home/team01/doc and
nameitprograma:
$pwd
/home/team01/doc
$cp/home/team03/pgms/subaprograma

before

home

after

home

team01

team01

doc

doc
mon_report
trio_ltr
walrus

mon_report
programa
trio_ltr
walrus

CopyrightIBMCorporation2008

Figure52.CopyingFiles

AU1310.0

Notes:
Copyingfiles
Thecpcommandcopiesfromoneormoresourcefilestoatargetfile.Thesourceis
usuallyanordinaryfile,butcanalsobeadirectoryfileiftheR(recursive)optionis
used.

CopyrightIBMCorp.1995,2008

Unit5.UsingFiles

53

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

87/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

StudentNotebook

cpExamples
$cd/home/team01
$cpdoc/programatest1c
home

home

team01

team01

doc
programa

.profile
manuals
test1

doc
programa
test1

programa

.profile
manuals
test1

$cd/home/team01/doc
$cptrio_ltr../c
home

home

team01

team01

doc

c
trio_ltr

doc
trio_ltr

trio_ltr

CopyrightIBMCorporation2008

Figure53.cpExamples

AU1310.0

Notes:
Copyingmultiplefiles
Thecpcommandcancopymultiplefilestoatarget.Inthatcase,thetargetmustbea
directory.

Targetexists
Whenusingthecpcommand,ifthefilespecifiedasthetargetfilealreadyexists,then
thecopyoperationwilloverwritetheoriginalcontentsofthefilewithoutwarning.To
avoidthisusethei(interactivecopy)option.

Targetisadirectory
Ifthetargetisadirectory,thesourcefile(s)willbecreatedwithinthedirectory,and
retainthesamefilename(s).

54AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty Recursivecopy
cpRcanbeusedtorecursivelycopyallfiles,subdirectories,andthefilesinthose
subdirectoriestoanewdirectory.Forexample:
cpR/home/team01/mydir/home/team01/newdir

Question:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

88/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Whatcommandwouldyouusetocopythefile/public/phonebook intoyourcurrent
directory?(Hint:Youdonotneedtoknowwhatyourcurrentdirectoryis.)

CopyrightIBMCorp.1995,2008

Unit5.UsingFiles

55

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

MovingandRenamingFiles
mvsourcetarget
mvfile1file2...target_dir
$pwd
/home/team01/c
$mvtrio_ltrt.letter

home

home

team01

team01

http://ss.hnu.cn/unix/ebook/aixbasics1.html

89/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

c
trio_ltr

t.letter

CopyrightIBMCorporation2008

Figure54.MovingandRenamingFiles

AU1310.0

Notes:
Themvcommand
Themvcommandmovesfilesanddirectoriesfromonedirectorytoanotherorrenames
afileordirectory.Ifyoumoveafileordirectorytoanewdirectory,itretainsthebasefile
name.Whenyoumoveafile,alllinkstootherfilesremainintact,exceptwhenyou
moveittoadifferentfilesystem.Whenyoumoveadirectoryintoanexistingdirectory,
thedirectoryanditscontentsareaddedundertheexistingdirectory.
Whenyouusethemvcommandtorenameafileordirectory,thetargetcanspecify
eitheranewfilenameoranewdirectorypathname.

56AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

mvExamples
$pwd
/home/team01/c
$mvt.letter../doc/letter
home

home

team01

team01

doc
t.letter

doc
trio_ltr
letter

trio_ltr

$pwd
/home/team01/c
$mv../doc/mon_report.
home

home

team01

team01

doc
mon_report

doc
mon_report

CopyrightIBMCorporation2008

Figure55.mvExamples

AU1310.0

Notes:
Movingfiles
http://ss.hnu.cn/unix/ebook/aixbasics1.html

90/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Asaresultofthemvcommand,youwillstillhavethesamenumberoffilesasyoudid
before.Furthermore,alltheattributesremainthesame.Theonlythingsthatchangeare
thefilenameandlocation.

Commandarguments
Thesourcecanbeafileoralistoffiles.Ifthesourceisalistoffiles,thenthetarget
mustbeadirectory.
Thetargetcanbeafileoradirectory.Warning! Ifthetargetisthenameofafilethat
alreadyexistsandifyouhavethecorrectpermissionssetforthatfileanddirectory,you
willoverwritethefileandnevergetanerrormessage.Toavoidthis,usemvi,an
interactivemovewhichpromptsyouifthereareduplicatenames.

CopyrightIBMCorp.1995,2008

Unit5.UsingFiles

57

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

ListingFileContents
catfile1file2...
$catwalrus
"Thetimehascome,"theWalrussaid,
"Totalkofmanythings:
Ofshoesandshipsandsealingwax
Ofcabbagesandkings
Andwhytheseaisboilinghot
Andwhetherpigshavewings."
FromTheWalrusAndTheCarpenter
byLewisCarroll(1871)

CopyrightIBMCorporation2008

Figure56.ListingFileContents

AU1310.0

Notes:
Introduction
Thecatcommanddisplaysthecontentsofallthefilesthatarespecifiedasarguments
tothecommand.

Toomuchoutput?
Thecatcommanddoesnotpaginatetheoutput.Ifitislongerthanascreen,thefilewill
scrolluntilthebottomofthefileisreached.Thus,youmayonlybeabletoreadthelast
fullscreenofinformation.

Linenumbers
http://ss.hnu.cn/unix/ebook/aixbasics1.html

91/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Todisplayallthelinesofafile,withnumbersdisplayedbesideeach,usethenflag.

58AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

DisplayingFiles
pgfilename
morefilename
$pgwalrus
"Thetimehascome,"theWalrussaid,
"Totalkofmanythings:
Ofshoesandshipsandsealingwax
Ofcabbagesandkings
Andwhytheseaisboilinghot
Andwhetherpigshavewings."
: <Enter>
$morewalrus
"Thetimehascome,"theWalrussaid,
"Totalkofmanythings:
Ofshoesandshipsandsealingwax
Ofcabbagesandkings
Andwhytheseaisboilinghot
Andwhetherpigshavewings."
walrus(100%) <Enter>

onepageatatime
CopyrightIBMCorporation2008

Figure57.DisplayingFiles

AU1310.0

Notes:
Displayingfiles
Thepgcommandreadsthefilenamesspecifiedanddisplaysthefilesonepageata
time.Eachscreenisfollowedbyaprompt.Press<Enter>todisplaythenextpage
downandhtogethelpinformation.
Themorecommandworksinmuchthesamewayasthepgcommanditdisplays
continuoustextonescreenatatime.Itpausesaftereachscreenandprintstheword
Moreatthebottomofthescreen.IfyoupressEnter,itdisplaysanadditionalline.Ifyou
pressthe<spacebar>,itdisplaysthenextscreenoftext.

Searchfunction
Bothpgandmoresupportsearchingthroughthefileforpatterns.morealsosupports
searchpatternhighlighting.

CopyrightIBMCorp.1995,2008

Unit5.UsingFiles

59

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

92/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

wcCommand
The wccommandcountsthenumberoflines,words,andbytesina
namedfile:
$wc[c][l][w]filename
Options:
c
l
w

countsthenumberofbytes
countslines
countswords

Example:
$wcmyfile
17

126

1085myfile
characters
words
lines
CopyrightIBMCorporation2008

AU1310.0

Figure58.wc Command

Notes:
Countingfilecontents
Whenfilesarespecifiedwiththewccommand,theirnameswillbeprintedalongwith
thecounts.Ifoptionsarenotused,theorderoftheoutputwillalwaysbelines,words,
andcharacters.

510AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Activity:WorkingwiththewcCommand

Activity
http://ss.hnu.cn/unix/ebook/aixbasics1.html

93/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorporation2008

Figure59.Activity:WorkingwiththewcCommand

AU1310.0

Notes:
Activity
__1.Logintothesystemwithyourteamxx IDandpassword.
__2.Executethewccommandandcountlinesinfile.profile .
__3.Executethewccommandandcountthebytesinfile.profile .
__4.Executethelslacommandonthefile.profile .Comparethisnumberwiththe
outputofinthepreviousstep.

CopyrightIBMCorp.1995,2008

Unit5.UsingFiles

511

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

ActivitywithHints
__1.Logintothesystemwithyourteamxx IDandpassword.
login:teamxx(attheloginprompt)
Password:teamxx(defaultpasswordsameasusername)
__2.Executethewccommandandcountlinesinfile.profile .
$wcl.profile
__3.Executethewccommandandcountthebytesinfile.profile .
$wcc.profile
__4.Executethelslacommandonthefile.profile .Comparethisnumberwiththe
outputofinthepreviousstep.
$lsla.profile

http://ss.hnu.cn/unix/ebook/aixbasics1.html

94/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

512AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

LinkingFiles
lnsource_filetarget_file
Allowsfilestohavemorethanonenameinthedirectorystructure
Bothfilesreferencethesameinode
Cannotbeusedwithdirectories,cannotspanfilesystems
$lsli
63rwrr

2team01staff

1910Nov2114:19man_files

$lnman_filesmanuals
$lsli
63rwrr
63rwrr

2team01staff
2team01staff

1910Nov2114:19man_files
1910Nov2114:19manuals

CopyrightIBMCorporation2008

Figure510.LinkingFiles

AU1310.0

Notes:
Introduction
Thelncommandinitssimplestofformsallowsonefiletohavetwoormoredifferent
http://ss.hnu.cn/unix/ebook/aixbasics1.html

95/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

namesinthedirectorystructure.Thesemultiplereferencesarealsoknownashard
links.Nocopyofthefiletakesplaceeachreferenceinthedirectorypointstothesame
inode.
Allothercharacteristicsoftheoriginalfilearereflectedinthenewfilereference.Thatis,
permissions,ownership,size,andmodificationtimeallremainthesame.Anychanges
toeitherfilewillbereflectedintheother.
Whenusingthelncommand,thesourceistheexistingfile,andthetargetisthenew
filereference(orlink)tobecreated.
ThesetypesoffilereferencescanonlybecreatedwithinthesameAIXfilesystem(or
partition).

CopyrightIBMCorp.1995,2008

Unit5.UsingFiles

513

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

LinkingFiles(cont.)
lnssource_filetarget_file
Createsanindirect referencetoafile( symboliclink )
Namereferencestheoriginalfilesnameandpath
Canbeusedwithdirectoriesandspanfilesystems
$
l
s

l
i
63

r
w

rr

2team01staff

1910Nov2114:19man_files

$ lnsman_filesmanuals
$3
l
s

l
i
6

r
w

rr
66lrwxrwxrwx

1team01staff
1team01staff

1910Nov2114:19man_files
1910Nov2114:19manuals>man_files

CopyrightIBMCorporation2008

Figure511.LinkingFiles(cont.)

AU1310.0

Notes:
Introduction:
Thelncommandalsoallowsforthecreationofindirectreferencestofiles.Theseare
calledsymboliclinks,andarecreatedusingthesoption.
Whenasymboliclinkiscreated,thedirectoryentryreferencesthenameofthesourcefile,
ratherthantheinode.Theycanbeusedwithdirectoriesaswellasfiles,andcanspan
physicalfilesystems.
Inthels loutputabove,thesymboliclinkisvisibleinthefilepermissionbitsthefirst
characterisanl(lowercasel).Also,inthelinkfilename,youcanseethereferencetothe
sourcefile.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

96/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

514AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

RemovingFiles
rmfile1file2file3...

$ls
mon_reporttrio_ltrwalrus
$rmmon_report
$ls
trio_ltrwalrus
$rmiwalrus
rm:removewalrus?y
$ls
trio_ltr
$
CopyrightIBMCorporation2008

Figure512.RemovingFiles

AU1310.0

Notes:
Methodsofremovingentries
Thermcommandremovestheentriesforthespecifiedfileorfilesfromadirectory.By
default,thereisnoconfirmationbeforetheentryisdeleted.Toincludeaconfirmation,
usethei(interactive)option.
Theroptionpermitsrecursiveremovalofdirectoriesandtheircontentsifadirectoryis
specified.Usethisoptionwithcare,asitdoesnotrequirethedirectorytobeemptyin
orderforthisoptiontowork.

CopyrightIBMCorp.1995,2008

Unit5.UsingFiles

515

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

97/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

PrintingFiles

qprtqueuefilestotheprinter

qchkdisplaythecurrentstatusofaprintqueue

qcancancelaprintjob(specifyjobnumber)
$qprtwalrus
$qchk
QueueDevStatusJobFilesUser
lp0
lp0Running 99walrusteam01

PP%BlksCpRnk
1
1 1 1

$qcanx99
$

CopyrightIBMCorporation2008

Figure513.PrintingFiles

AU1310.0

Notes:
Printsubsystems
AIXsupportstwoprintingsubsystems:theSystemVPrintingSubsystemandtheAIX
PrintingSubsystem.

Printingfiles
Theprinterqueuemechanismofeithersubsystemallowsmultipleuserstousethe
sameprinterwithoutauserhavingtowaitfortheprintertobeavailable.
Toqueueafileforprintingthereareanumberofcommandsavailable(toremain
compatiblewithotherversionsofUNIX).Theyareqprt,lp,lpr.Thecommandqprt
hasthemostfacilities.

Tospecifyaprinter(otherthanthedefault)usethePoptiontotheqprtcommand.For
example,tosendafiletoqueuelp1use:
516AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

$qprt Plp1filename
Toobtainthejobnumberofyourprintrequestusethe#joptionwiththeqprt
commandatthetimeofsubmission.

Printcommanddifferences
Alternativecommandsexistforprinting.Theyare:
AT&T
$lpfilename

BSD
$lprfilename

Thefollowingcommandsareavailabletolistandcanceljobsintheprintqueues:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

98/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

AT&T
$lpstat

BSD
$lpq

Displayingqueueinformation
Theqchkcommandbydefaultwillonlylistinformationaboutthedefaultqueue.To
obtainalistingforallthequeuesdefinedonyoursystemusetheAoptionorusethe
lpstatcommand.
Theqcancommandcanbeusedtocancelonefileinaqueuewhenusedwiththex
option.Itcanalsobeusedtocancelallyourjobsinaparticularqueuewhenusedwith
theXoptionthatis:
$qcanXPlp0

CopyrightIBMCorp.1995,2008

Unit5.UsingFiles

517

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Checkpoint
1. Whatistheeffectofthefollowingcommands?
$cd/home/team01
$cpfile1file2

2. Whatistheeffectofthefollowingcommands?
$cd/home/team01
$mvfile1newfile

3. Whatistheeffectofthefollowingcommands?
$cd/home/team01
$lnnewfilemyfile

http://ss.hnu.cn/unix/ebook/aixbasics1.html

99/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

4. Listcommandsthatcanbeusedtoviewthecontentsofafile.
CopyrightIBMCorporation2008

Figure514.Checkpoint

AU1310.0

Notes:

518AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Exercise:UsingFiles

CopyrightIBMCorporation2008

Figure515.Exercise:UsingFiles

AU1310.0

Notes:
Aftercompletingthelab,youwillbeableto:
Copy,move,link,andremovefiles
Displaythecontentsofafileusingdifferentcommands
Printafile
http://ss.hnu.cn/unix/ebook/aixbasics1.html

100/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit5.UsingFiles

519

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

UnitSummary
The cpcommandcanbeusedtocopyfiles.
The mvcommandcanbeusedtomoveandrenamefiles.
The lncommandcanbeusedtocreateadditionalnamesfor
afile.
Displaythecontentsofafileusingcat, pg,ormore.
Usethermcommandtodeletefiles.
Usetheqprtcommandtoprintfiles.
The wccommandcouldbeusedtocountwordsorlinesfrom
filesorcommandoutput.

CopyrightIBMCorporation2008

Figure516.UnitSummary

AU1310.0

Notes:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

101/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

520AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Unit6.FilePermissions
WhatThisUnitIsAbout
Thisunitintroducesthestudentstotheconceptofprotectingfilesfrom
unauthorizedaccessbycontrollingafile'spermissions.

WhatYouShouldBeAbletoDo
Aftercompletingthisunit,studentsshouldbeableto:
Listthebasicfilepermissions
Changethebasicfilepermissionsusingboththeoctaland
symbolicformats

HowYouWillCheckYourProgress
Accountability:
StudentActivity
Checkpointquestions
Exercise

CopyrightIBMCorp.1995,2008

Unit6.FilePermissions

61

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

102/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

UnitObjectives
Aftercompletingthisunit,youshouldbeableto:
Listthebasicfilepermissions
Change thebasicfilepermissions usingboththeoctaland
symbolicformats

CopyrightIBMCorporation2008

Figure61.UnitObjectives

AU1310.0

Notes:

62AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

LongListingofFiles
The lscommandwiththe loptioncanbeusedtoobtainmore
informationaboutthefilesinadirectory.
$lsl
drwxrwxrx
drwxrwxrx
rwxrwxrx
rwxrwxrx

http://ss.hnu.cn/unix/ebook/aixbasics1.html

2team01
2team01
1team01
2team01

staff 1024
staff 512
staff 320
staff 144

Aug12
Feb18
Feb22
Feb22

10:16c
09:55doc
07:30suba
16:30test1

103/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

PermissionBits

CopyrightIBMCorporation2008

Figure62.LongListingofFiles

AU1310.0

Notes:
Introduction
Aninodedescribesafileordirectoryentryasitappearsonadisk.Eachfilehasone
inodeassignedtoit.Theinformationthatisdisplayedfromthelslcommand(as
shownontheabovevisual)isreadfromtheinodesassociatedwiththefileslisted.

CopyrightIBMCorp.1995,2008

Unit6.FilePermissions

63

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

lscommandoutput
Thefieldsfromthe lslcommandareasfollows:
(1)

(2)

(3)

(4)

(5)

(6)

(7)

drwxrwxrx

team01

staff

1024

Aug12

10:16

drwxrwxrx

team01

staff

512

Feb18

09:55

doc

rwxrwxrx

team01

staff

320

Feb22

07:30

suba

rwxrwxrx

team01

staff

144

Feb22

16:30

test1

Field1showsthefile/directoryandpermissionbits
Field2isthelinkcount
Field3showstheusernameofthepersonwhoownsentry
Field4showsthenameofthegroupforwhichgroupprotectionprivilegesarein
effect
Field5showsthecharactercountoftheentry
Field6showsthedateandtimethefilewaslastmodified
Field7showsthenameofthefile/directory
The doptionusedwiththe loptionofthelscommandisanotherveryuseful
option.Thedoptionwilldisplayonlytheinformationaboutthedirectoryspecified.
Directoriesaretreatedlikeordinaryfiles.
http://ss.hnu.cn/unix/ebook/aixbasics1.html

104/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

64AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

FileProtection/Permissions
Everyfileanddirectoryonthesystemhasfilepermissionsassociatedwithit.
Threepermissioncategories:owner , group , and other
Threebitscanbesetforeachcategory:read,write,execute(rwx)

Foranordinary file:
r=>Canlookatthecontentsofafile
w=>Canchangeordeletethecontentsofafile
x=>Canexecutethefile( r isalsoneededifascript)

Foradirectory :
r=>Canlistthefileswithinadirectory( ls)
w=>Canmodify/removefilesinthedirectory
x=>Canchangeintothedirectoryandaccessthefileswithin( cd)

CopyrightIBMCorporation2008

Figure63.FileProtection/Permissions

AU1310.0

Notes:
Filepermissions
Thevisualdescribesthethreepermissioncategories,andtheassociatedpermissionbits
thatcanbesetforeach.
Forfiles,thepermissionbitsarestraightforward.Forshellscripts,therbitisrequiredwith
thextomakethefileexecutable.Compiled(binary)programsonlyrequirethex.
http://ss.hnu.cn/unix/ebook/aixbasics1.html

105/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Fordirectories,thexbitisrequiredtoaccessanyofthefilesorsubdirectorieswithinit.This
impliesthatthexbitisrequiredonalldirectoriesaboveitaswell.
Thewbitonadirectoryoverridesanypermissionsonthefileswithinthatdirectory.Thus,if
auserhaswriteaccesstoadirectory,theycanremoveANYfilesordirectorieswithinit,
regardlessoftheindividualfilespermissions.

CopyrightIBMCorp.1995,2008

Unit6.FilePermissions

65

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

ChangingPermissions(SymbolicNotation)
chmodmodefilename
u =ownerofthefile
+ :addpermissions
:removepermissions
g =owner'sgroup
o =otherusersonthesystem = :clearspermissionsandsetstomodespecified
a =all
$lslnewfile
rwrr1team01

staff

58Apr21 16:06

newfile

$chmodgo+wnewfile
$lslnewfile
rwrwrw1team01

staff

58Apr21 16:06

newfile

$chmoda+xnewfile
$lslnewfile
rwxrwxrwx1team01 staff

58Apr21 16:06

newfile

$chmodorwxnewfile
$lslnewfile
rwxrwx1team01

58Apr21 16:06

newfile

staff

CopyrightIBMCorporation2008

Figure64.ChangingPermissions(SymbolicNotation)

AU1310.0

Notes:
Symbolicnotation
Withsymbolicnotation,youarespecifyingchangesrelativetotheexistingpermissions
onafileordirectorybyaddingordeletingpermissions.Youcancheckwhatthe
permissionsarecurrentlysettobyusingthelslcommand.
Youcanspecifymultiplesymbolicmodesseparatedwithcommas.Donotseparate
itemsinthislistwithspaces.Operationsareperformedintheordertheyappearfrom
lefttoright.
WhenyouusetheSymbolicmodetospecifypermissionmodes,thefirstsetof
parametersselectsthepermissionfield,asfollows:
uFileowner
gGroup
oAllothers
66AIX6Basics

http://ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

106/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

aUser,group,andallothers.Thishasthesameeffectasspecifyingtheugo
options.Theaoptionisthedefaultpermissionfield.Ifthepermissionfieldis
omitted,thedefaultistheaoption.
Thesecondsetofflagsselectswhetherpermissionsaretobetakenaway,added,or
setexactlyasspecified:
Removesspecifiedpermissions
+Addsspecifiedpermissions
=Clearstheselectedpermissionfieldandsetsittothemodespecified.Ifyou
donotspecifyapermissionmodefollowing=,thechmodcommandremoves
allpermissionsfromtheselectedfield.
Thethirdsetofparametersofthechmodcommandselectsthepermissionsasfollows:
rReadpermission
wWritepermission
xExecutepermissionforfilessearchpermissionfordirectories.

CopyrightIBMCorp.1995,2008

Unit6.FilePermissions

67

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

ChangingPermissions(OctalNotation)
http://ss.hnu.cn/unix/ebook/aixbasics1.html

107/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Fileanddirectorypermissionscanbespecifiedinthesymbolic
syntaxorasanoctalnumber :
User
rwx
111
4+2+1
7

Symbolic
Binary
Octal

Others
r
100
4+0+0
4

Group
rw
110
4+2+0
6

Tochangepermissionssotheowner and group have read and write


permissionsandothersreadonly :
$lslnewfile
rwrr 1team01staff

58Apr2116:06newfile

$chmod664newfile
$lslnewfile
1
team01staff
rwrwr

65Apr2217:06newfile

CopyrightIBMCorporation2008

Figure65.ChangingPermissions(OctalNotation)

AU1310.0

Notes:
Permissionnotation
Eachpermissioninthegroupofnineisrepresentedbyaoneandalackofpermission
isrepresentedbyazero.Sorwrrtranslatesto110100100inbinary,or644inoctal
notation.
Whenusingoctalnotation,allpermissionbitsmustbesetyoucannotchange
permissionsononecategory(thatis,justtheowner,orjustthegroup).

68AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Translatingpermissions
Thechartbelowmayhelpintranslatingbinarytooctalforthosewhoareunfamiliarwith
binarynotation:
user

group

others

r
|

w
|

x
|

r
|

w
|

x
|

r
|

w
|

x
|

|
|

|
|

|
|

|
|

|
|

|
|

|
|

|
|

|
|

400

|
|

|
|

40

|
|

|
|

|
|

|
|

200

|
|

20

|
|

|
|

http://ss.hnu.cn/unix/ebook/aixbasics1.html

108/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

100
10
1
Inordertotranslatethemodeyourequiretoanumber,addthenumberscorresponding
tothepermissionsyouneed.So,ifyouneedthefiletobereadableandwritablebythe
ownerandgroup,andreadablebyalltheotherusersofthesystem,simplyperformthe
addition:
400
200
40
20
4
____
664
____
Thechmodcommandwouldbe:
$chmod664newfile
Withtheoctalformat,youspecifyafile'sfinalpermissions.

Warningmessages
Sometimesthefilepermissionwillgenerateasafetyprompt,ratherthantotally
preventingyoufromcompletingtheoperation.Forexample,ifyouaretheownerofa
file,youhavenopermissionsonthatfile(forexample000),andyoutrytoremoveit,the
systemwillaskyouifyouwanttooverridetheprotectionsettingonthefilethatyouwish
toremove.Youmayrespondyesatthispoint,andthesystemwillremoveyourfile.The
samewillhappenifyouareamemberofthegroup.

CopyrightIBMCorp.1995,2008

Unit6.FilePermissions

69

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

DefaultFilePermissions

Thedefaultprotectionsfornewlycreatedfilesanddirectoriesare:

File

rwrr

644

Directory drwxrxrx

755

Thesedefaultsettingsmaybechangedbychangingtheumaskvalue.

CopyrightIBMCorporation2008

Figure66.DefaultFilePermissions

http://ss.hnu.cn/unix/ebook/aixbasics1.html

AU1310.0

109/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Notes:
Systemdefaults
Therealdefaultpermissionsforafileanddirectoryare666and777respectively.The
umaskvalueisthensubtractedfromthesevalues.Thedefaultumaskis022,which
leavesyouwithvaluesof644forafileand755foradirectory.

610AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

umask

The umaskspecifieswhatpermissionbitswillbesetonanewfile
or directory whencreated.Itisanoctalnumber thatisusedto
determinewhatpermissionbitsafileordirectoryiscreatedwith:

NewDirectory:777022: 755
NewFile:
666022: 644

=>rwxrxrx
=>rwrr

Thedefaultvalueof022 issetin /etc/security/user . Itcanbe


changedforallusersorforaspecificuser.

CopyrightIBMCorporation2008

Figure67.umask

AU1310.0
.

Notes:
Understandingpermissions
umaskisacommandwhichsetstheumaskvaluebyacceptinganoctalpermissionstring
asanargument.Ifanargumentisnotprovidedthenumaskwilldisplaytheexisting
umaskvalue.
Thechmodcommandworksbyapplyingapermissionsmaskontoafile.umask,onthe
otherhand,worksbytakingawaythesepermissions.
Thedefaultsettingoftheumaskis022.Fortightersecurity,youshouldmaketheumask
http://ss.hnu.cn/unix/ebook/aixbasics1.html

110/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

027oreven077.
Aumaskof022specifiesthatthepermissionsonanewfilewillbe644oronanew
directorywillbe755.Aumaskof000wouldgive666permissionsonafile(read/write
accesstoall)or777onadirectory(read/write/executeaccesstoall).
Executepermissionsareneversetwhenordinaryfilesarecreated.

CopyrightIBMCorp.1995,2008

Unit6.FilePermissions

611

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Permissionoctalformat
Remember,thepermissions,inoctal,are:
0
0
0 =nothing
1
1
1 =eXecute
2
2
2 =Write
4
4
4 =Read
___
___
___
usergroupothers
Usingchmod,permissionsaregrantedbysummingtheoctalvaluesforeachcategory
(user,grouporothers),forexample644means(2+4)(4)(4)or(w+r)(r)(r).

612AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

111/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

V3.1
StudentNotebook

Uempty

Activity:PersonalDirectories

Activity

CopyrightIBMCorporation2008

Figure68.Activity:PersonalDirectories

AU1310.0

Notes:
Activity
Inthisactivityyouwillreviewtheumaskandchmodcommands.
__1.Logintothesystem.
__2.Executetheumaskcommandandwritedowntheumaskyouareusing:

__3.Accordingtoyourumask,whatdefaultfilepermissiondoyouexpectforanew
directoryoranewfile?
Newdirectory:_________
Newfile:

CopyrightIBMCorp.1995,2008

Unit6.FilePermissions

613

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

__4.Createanewdirectorytestdir1 andcheckthefilepermissions.
__5.Createanewfiletestfile1 andcheckthefilepermissions.
__6.Executethecommandumask027tochangeyourdefaultumask.
__7.Createanewdirectorypersonal andcheckthefilepermissions.Whatdifferencedo
yousee?
http://ss.hnu.cn/unix/ebook/aixbasics1.html

112/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

__8.Inaprivatedirectorywherepersonalfilesarestored,youshouldpreventothersfrom
accessingthisdirectory.Executethechmodcommandandprotectyourpersonal
directory.
Writedownthecommandyouexecuted:

__9.Executelsldpersonalandcheckthattherightsarecorrect.
Pleaseresettheumasktothevaluefoundinstep2orlogoutandloginagain.

Optionalactivity:
__10.Verifywiththettycommandonwhichterminalyouareworking.Displaythe
permissionsofthatterminalwiththecommandlsl$(tty).Nowusethe
commandmesgwithoptionyorntoallowordenymessagesviawriteorwall
commandstothisterminal.Displaythepermissionsagain.Whatdoesthemesg
commanddo?

614AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Function/PermissionsRequired
Command

SourceDirectory SourceFile

TargetDirectory

cd

N/A

N/A

ls

N/A

N/A

lsl

r,x

N/A

N/A

N/A

N/A

N/A

N/A

N/A

mkdir

x
w(parent)
rmdir
x
w(parent)
cat,pg,more x
mv
http://ss.hnu.cn/unix/ebook/aixbasics1.html

113/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

cp

x,w
x

NONE
r

x,w
x,w

touch

x,w*

NONE

N/A

rm

x,w

NONE

N/A

CopyrightIBMCorporation2008

Figure69.Function/PermissionsRequired

AU1310.0

Notes:
Filepermissions
Thistablecanbeusedasareferencetoensurethatthecorrectpermissionsareseton
filesanddirectoriestoaccomplishthedesiredactivity.
*wpermissionisalsoneededinthesourcedirectorywhenusingthetouchcommand
tocreateazerolengthfile.wpermissionisnotnecessaryifusingthetouchcommand
onanexistingfileforthepurposeofupdatingthemodificationdate.

CopyrightIBMCorp.1995,2008

Unit6.FilePermissions

615

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Checkpoint(1of3)
Thefollowingquestionsareforafilecalledreporta whichhasthe
followingsetofpermissions:rwxrxrx
1. Whatisthemodeinoctal?
2. Changemodetorwxrr usingsymbolicformat.
3. Repeattheaboveoperationusingoctalformat.
Questionfourisbasedonthefollowinglisting.Assumethatthe
directoryjobs containsthefilejoblog .
$lslR
total8
drwxrxrx 2 judyfinance

512June5

11:08 jobs

./jobs:
total8
rwrwr 1judyfinance

100June6

12:16 joblog

4. CanFred,whoisamemberofthefinancegroup,modifythefile
joblog ?
CopyrightIBMCorporation2008

Figure610.Checkpoint(1of3)

AU1310.0

Notes:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

114/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

616AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Checkpoint(2of3)
Thisquestionisbasedonthefollowinglisting.Assumethatthe
directoryjobscontainsthedirectorywork,whichinturncontainsthe
file joblog .
$lslR
total8
drwxrwxrx 3judyfinance

512June5

11:08jobs

./jobs:
total8
drwxrwrx 2judyfinance

512June5

11:10 work

./jobs/work:
total8
rwrwr 1judyfinance

100June6

12:16 joblog

5. CanFred,whoisamemberofthefinancegroup,modifythefile
joblog ?
CopyrightIBMCorporation2008

Figure611.Checkpoint(2of3)

AU1310.0

Notes:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

115/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit6.FilePermissions

617

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Checkpoint(3of3)
Thisquestionisbasedonthefollowinglisting.Assumethatthe
directoryjobscontainsthedirectorywork,whichinturncontainsthe
file joblog .
$lslR
total8
drwxrxrx 3judyfinance

512June5

11:08 jobs

./jobs:
total8
drwxrwxrwx 2judyfinance

512June5

11:10 work

./jobs/work:
total8
rwrwr 1judyfinance

100June6

12:16 joblog

6. CanFred,whoisamemberofthefinancegroup,copythefilejoblog
tohishomedirectory?
CopyrightIBMCorporation2008

Figure612.Checkpoint(3of3)

AU1310.0

Notes:

618AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

116/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

V3.1
StudentNotebook

Uempty

Exercise:FilePermissions

CopyrightIBMCorporation2008

Figure613.Exercise:FilePermissions

AU1310.0

Notes:
Aftercompletingtheexercise,youwillbeableto:
Manipulatepermissionsonordinaryfilesanddirectories
Interpretfileanddirectorypermissionbits

CopyrightIBMCorp.1995,2008

Unit6.FilePermissions

619

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

UnitSummary
Basic filepermissionscanbelistedusingthels l
command.
http://ss.hnu.cn/unix/ebook/aixbasics1.html

117/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

chmodgrantsorremovesread,write,andexecute
permissionsforthreeclassesofusers:user , group and
others .
Thepermissionsusedwiththechmodcommandcanbe
definedinsymbolicoroctalformat.
The umaskspecifiesthepermissionsfornewfilesand
directories.

CopyrightIBMCorporation2008

Figure614.UnitSummary

AU1310.0

Notes:

620AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Unit7.TheviEditor
WhatThisUnitIsAbout
Thisunitisanintroductiontothevieditor.Itdescribeshowtobegin
aneditsession,addtext,removetext,andsavetextwithinafile.

WhatYouShouldBeAbletoDo
Aftercompletingthisunit,studentsshouldbeableto:
Createandeditfiles
Manipulatetextwithinafile
Setupdefaultsforthevieditor
Executecommandlineediting
Definetheusesfortheotherformsofvi
http://ss.hnu.cn/unix/ebook/aixbasics1.html

118/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

HowYouWillCheckYourProgress
Accountability:
Studentactivity
Checkpointquestions
Exercise

CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

71

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

UnitObjectives
Aftercompletingthisunit,youshouldbeableto:
Create and edit files
Manipulatetext withinafile
Setupdefaults forthevieditor
Execute commandlineediting
Definetheusesfortheotherformsofvi

CopyrightIBMCorporation2008

Figure71.UnitObjectives

AU1310.0

Notes:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

119/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

72AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

IntroductiontotheviEditor

Fullscreen editor

Twomodes ofoperation:command and text

Utilizes onelettercommands

Doesnotformattext

Flexiblesearchandreplacefacilitywithpatternmatching

Allowsforuserdefinededitingfunctionsusingmacros
CopyrightIBMCorporation2008

Figure72.Introductiontothevi Editor

AU1310.0

Notes:
Thevieditor
Itisimportanttoknowviforthefollowingreasons:
ItistheonlyeditoravailableinmaintenancemodeonIBMSystemp
StandardeditoracrossallUNIXsystems
Commandlineeditingfeature
Usedasdefaulteditorforsomeprograms

Modesofoperation
Thevieditorhastwomodesofoperation.Commandmodeallowstheusertoperform
http://ss.hnu.cn/unix/ebook/aixbasics1.html

120/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

operationsonthetext,suchascut,paste,cursormovement,andreplacement.These
operationsareallinvokedbyonecharactercommands.Textmode(alsoknownas
insertmode)allowstheusertoentertextallcharacterstypedareinsertedintothefile.
CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

73

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Thereisnowaytotellwhichmodetheeditorisin,otherthanpressingakeyonthe
keyboard.Ifthekeyyoupressisinsertedintothefile,thecurrentmodeistextmode.If
thekeyperformsanaction,thecurrentmodeiscommandmode.
Switchingfromcommandmodetotextmodeisdonewithoneoftheinserttext
commands,whichwillbecoveredlater.Returningtocommandmodeisdoneby
pressingthe<Esc>key.

Advancedfeatures
Thevieditorhasmanyadvancedfeatures,suchasflexiblesearchandreplace(using
standardregularexpressions),undo,anduserdefinededitingfunctions(called
macros).
ItisimportanttorememberthatthevieditoreditsASCIItextfilesdirectlyitdoesnot
formatthetextinanyway,asawordprocessorwoulddo.

Introductiontovifunctions
Thisunitcoversonlyasubsetofthevifunctions.Itisaverypowerfuleditor.Referto
theonlinedocumentationforadditionalfunctions.RefertotheCommandSummaryin
theappendicesforareferenceguideonusingvi.

74AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

121/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Uempty

Starting vi
$vivifile
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"vifile"
[Newfile]

Ifthefile"vifile" doesnotexist,itwillbecreated

Otherwise, viwillopentheexistingfile
CopyrightIBMCorporation2008

Figure73.Startingvi

AU1310.0
.

Notes:
Editorstartup
Whentheeditorstartsup,itneedstouseworkspacefortheneworexistingfileyouare
goingtoedit.Itdoesthisbyusinganeditingbuffer.Whenasessionisinitiated,oneof
twothingshappens:
Ifthefiletobeeditedexists,acopyofthefileisputintoabufferin/var/tmp by
default.
Ifthefiledoesnotexist,anemptybufferisopenedforthissession.
Thetildecharactersrepresentemptylinesintheeditor.
Theeditorstartsincommandmode.

CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

75

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

AddingText
$vivifile
keystroke

Thisfileisbeingcreatedusingthe
vieditor.
Tolearnmoreaboutthevieditor,

http://ss.hnu.cn/unix/ebook/aixbasics1.html

122/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

l
uo
no
dk
e
ri
n
v
it
.he"CommandsReference"manual
~
~
~
~
~
~
~
~
~
~
~

CopyrightIBMCorporation2008

Figure74.AddingText

AU1310.0

Notes:
Addingtexttoafile
Totypetextintoafile,thefollowingcommandscanbeused:
a

appendtextafterthecursor

appendtexttotheendoftheline

inserttextatthecursor

inserttextatthestartoftheline

openanewlineunderthecurrentline

openanewlineabovethecurrentline

Eachofthesecommandsplacesthesessionintotextmode.Anycharactersentered
willbeplacedintothefile.
Toexitfromtextmode,pressthe<Esc>key.
76AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

ExitingtheEditor
$vivifile
keystroke:
<Esc>

Thisfileisbeingcreatedusingthe
vieditor.
Tolearnmoreaboutthevieditor,
lookinthe"CommandsReference"manual
undervi.
~
~
~
~
~
~
~
~
~
~
~
~
~

:wq
http://ss.hnu.cn/unix/ebook/aixbasics1.html

123/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Toquitwithout saving:
Tosave and exit :

:q!
:xor:wqor<shiftzz>

CopyrightIBMCorporation2008

Figure75.ExitingtheEditor

AU1310.0

Notes:
Exitingtheeditor
Togetintocommandmode,ortoensurethatyouareincommandmode,press<Esc>
beforecarryingoutanycommands.
Thesecommandswillexittheeditor.Eachwillexitdifferently.
:q

quitswithoutsaving.Thisoptionwillonlyworkifyouhavenotmade
anychanges.Ifyouhavemadechanges,thentoforceanexitoutof
theeditor,use!withtheqcommand.

:w

writeschanges

:x

savesandexits

:wq

writeschangesandquits

<Shift+zz>writeschangesandquits
The :subcommandwillplacethecursoratthebottomofthescreen.
CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

77

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

CursorMovement
1G
<ctrlb>
H
k
<uparrow>
0
b,B
h
<leftarrow>

$
w,W
l
<rightarrow>

<downarrow>
j
L
<ctrlf>
G

CopyrightIBMCorporation2008

Figure76.CursorMovement

AU1310.0

Notes:
Movingwithinafile
Notethatforalltheuppercasespecifiedcommands,the<shift>keymustbeused.
http://ss.hnu.cn/unix/ebook/aixbasics1.html

124/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Thefollowingcommandsdescribedifferenttechniquesformovingaroundwithinafile.

Movingwithinaline
Tomovewithinalinemakesureyouareincommandmodeand:
<leftarrow>orh onecharacterleft
<rightarrow>orl onecharacterright
0
movetobeginningofline
$

movetoendofline

78AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Movingtoaword
Tomovetoaword:
w

nextsmallword

nextbigword

backtoprevioussmallword

backtopreviousbigword

endofnextsmallword

endofnextbigword

Movingwithinthescreen
Tomovewithinthescreen:
<uparrow>ork

onelineup

<downarrow>orj
H

onelinedown

middlelineonscreen

lastlineonscreen

toplineonscreen

Scrollingthescreen
Toscrollthescreen:
<ctrlf>

scrollforward

<ctrlb>

scrollbackward

Movingwithinthefile
Tomovewithinthefile:
1G

gotothefirstline

45G

gotolinenumber45

gotothelastline

http://ss.hnu.cn/unix/ebook/aixbasics1.html

125/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

79

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

DeletingText

Todeleteasinglecharacter :

Todeletetothe endofthecurrentword :

dw

Todeletetotheendoftheline :

d$

Todeletetothestartoftheline :

d0

Todeletethewholeline :

dd

Todeletearangeoflines :

:20,40d

Undo thelastchange:

CopyrightIBMCorporation2008

Figure77.DeletingText

AU1310.0

Notes:
Introduction
Toexecuteanyoftheillustratedcommands,youmustbeincommandmode.
Thereareseveraldifferentwaystoperformthedeletefunctions.SeetheAIX
documentationforothervideletefunctions.

710AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

126/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Uempty

SearchforaPattern
$vivifile
keystroke:

<Esc>
n

Thisfileisbeingcreatedusingthe
vieditor.
T
v
i

e
d
i
t
o
r
,
lo
o
ol
ke
a
ir
nn

tm
ho
er
e
"
Ca
ob
mo
mu
at
n
dt
sh
e
Re
f
e
r
e
n
c
e
"

manual
undervi.
~
~
~
~
~
~
~
~
~
~
~
/the

Tosearchforward,use/text
Tosearchbackward,use ?
text

CopyrightIBMCorporation2008

Figure78.SearchforaPattern

AU1310.0

Notes:
Searchingforpatterns
Whenincommandmode,pressing/automaticallyputsyouatthebottomofthefile,
readytotypeinasearchpattern.
/thesearchesforwardforthefirstoccurrenceofthewordthe.
?thesearchesbackwardforthefirstoccurrenceofthewordthe.
Pressingthenkeywillcontinuethesearchinthesamedirection(forwardif/wasused,
backwardif?wasused).
TheNkeywillcontinuethesearchintheoppositedirection.

CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

711

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Activity: viCommands
Assignthefollowingvicommands:
a,i,u,x,dd,G,1G,ESC,:q!,:wq
Quitwithoutsaving:
Deletethewholeline:
Exitfromtextmode:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

127/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Addtextaftercursor:
Undothelastchange:
Gotothelastline:
Deleteasinglecharacter:
Inserttextatthecursor:
Writechangesandquit:
Gotothefirstline:
CopyrightIBMCorporation2008

AU1310.0

Figure79.Activity:vi Commands

Notes:
Completethetableinthevisual.

712AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

ChangingText
$vivifile

keystroke:
<Esc>

Thisfileisbeingcreatedusingthe
vieditor.
Tolearnmoreabouttheoneandonlyvi
editor,
lookintheoneandonly"Commands
Reference"
manualundervi.
~
~
~
~
~
~
~
:g/the/s//theoneandonly/g

Textcanbereplacedbyovertyping: Rnewtext
rX (X=newcharacter)
Asinglecharactercanbereplaced:
c2w
Wordscanbechanged:
Oreveryoccurrenceofawordcanbesubstitutedforanotherwordor

http://ss.hnu.cn/unix/ebook/aixbasics1.html

128/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

words
CopyrightIBMCorporation2008

Figure710.ChangingText

AU1310.0

Notes:
Changingtext
Thecommand:g/the/s//theoneandonly/gfindseveryoccurrenceofthe
stringtheandreplacesitwiththeoneandonly.Noticethatitwouldnotreplacethe
theonthefirstlineoftext.Rememberaboutspaces:therewasnospacebetweenthe
theandthenewlinecharacter.
Thefirstgtellsthesystemtosearchforthefirstoccurrenceofthestringoneverylinein
thefile.
Thesstandsforsubstitute.Thenexttwoslashesdirecttheeditortousethesearch
stringusedintheprecedingcommand,inthisexamplethestringtheandreplaceitwith
thestringtheoneandonly.
Thelastgstandsforglobalanddirectsthechangetobemadeateveryoccurrence
acrosseachlinebeingsearched.

CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

713

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

TheRcommandwillplaceyouintextmodeandallowyoutoovertypetheexistingtext
beginningatthecurrentcursorposition.Thercommandwillplaceyouintextmodeand
allowyoutoovertypeonlytheletteratthecurrentcursorpositionafterreplacingthat
oneletteryouareplaceimmediatelybackintocommandmode.
Theccommandcanbeusedtospecifythescopeofwhatyouwanttoreplace,sothatif
youwanttoreplacetwowordsspanningoftotalof10characters,youcanreplacethem
withaverylongstring,suchas20characters,andnotoverwritethewordswhichfollow
thosetwowords.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

129/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

714AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Cut,Copy,andPaste
Commands
Thisisthefirstlineoftext
_Thisisthesecondlineoftext
Thisisthethirdlineoftext

dd

Thisisthefirstlineoftext
_Thisisthethirdlineoftext

Thisisthefirstlineoftext
Thisisthethirdlineoftext

_Thisisthesecondlineoftext

To cut text,usethedcommand.
To copy text,usetheycommand.

To paste thecutorcopiedtextonthelinebelowthecursor
position,usethepcommand.

CopyrightIBMCorporation2008

Figure711.Cut,Copy,andPaste

AU1310.0

Notes:
Howtocopy,cut,andpaste
Tocopyintoatemporarybuffer:
yy

placesthecurrentlineintoabuffer

Tocut(ormove)text:
dd
10dd

deletethecurrentline(andstoreitintheundobuffer)
deletethenext10lines(andplacethemintheundobuffer)

Toputtextback:
p

putstextbackafterthecursororonthenextline

putstextbackbeforethecursororonthepreviousline

TheucommandwillUNDOyourlastcommandifyoumakeanerror.So,ifyoudelete
somethinginerror,immediatelytypetheucommandtoretrieveit.
http://ss.hnu.cn/unix/ebook/aixbasics1.html

130/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

715

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Cuttingandcopyingmultiplelines
Multiplelinescancutorcopiedbyspecifyinganumbereitherinfrontoftheddoryy
command,orbetweenthelettersofthecommand.
10dd(ord10d)Cut10linesfromthecursorpositiondownintothebuffer.
15yy(ory15y)
Copy15linesfromthecursorpositiondownintothebuffer.

716AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty
http://ss.hnu.cn/unix/ebook/aixbasics1.html

131/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

viExecutingAIXCommands
$vimyfile
Thefollowingshouldbestockedinthe
employeebreakroom:

keystroke:

~
~
~

<Esc>

:!ls
file1file2snacks
[Hitreturntocontinue]
Thefollowingshouldbestockedinthe
employeebreakroom:

:rsnacks

candybars
sodapop
popcorn

CopyrightIBMCorporation2008

AU1310.0

Figure712.vi ExecutingAIXCommands

Notes:
Introduction
RatherthanendingavisessiontorunanAIXcommand,onlytohavetoreturntovi,
vigivesyouthecapabilitytotemporarilyaccessashellpromptthroughtheuseofthe
:!subcommand.Ifyouwanttopullincontentsofafileintoaneditingsession,vi
providesthe:rsubcommand.
Let'sassumethatthereisafileinyourcurrentdirectorythatneedstobepulledintothe
contentsofthisfile.Youdonotwanttohavetorekeyalltheinformationorredirectthe
informationafterexitingthevisession,plusyoucannotrememberthenameofthefile.
WhattheexampleshowsiscombiningavireadwithacalltoAIXtoreadthecontents
ofsnacks intoyoursession.

CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

717

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Executingasinglecommandfromwithinvi
:!lswillcreateashell.
Allfilesinthecurrentdirectoryarelisted.PressEntertoexittheshellandreturnto
thevisessionor,
Whilestillincommandmode,issuethe:rsnackscommand.Thecontentsofthe
filesnacksarereadintothevifile.Bydefault,itwillappearafterthecurrentline.
Bydefaultthedataisplacedatthecurrentline.Ifyouhavelinenumberingsettoon,
youcanprecedethe:rwithalinenumbertoplacethecontentsofthefileatanypoint
inthefile.

Executingmultiplecommandsfromwithinvi
http://ss.hnu.cn/unix/ebook/aixbasics1.html

132/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Ifyouneedtorunaseriesofcommandswithoutreturningtoviafterthefirstcommand
isexecuted,enter:sh.Whenyouhaverunallthecommands,press<Ctrld>toexit
theshellandreturntovi.

718AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

viOptions

Options enteredinthevisessionchangethebehaviorofthevi
command
:setall
:setautoindent/noautoindent
:setnumber/nonumber
:setlist/nolist
:setshowmode/noshowmode
:settabstop=x
:setignorecase/noignorecase
:setwrapmargin=5

Optionscanbestoredinthefile$HOME/.exrc

Macros canbewrittenandnewcommandscreated

CopyrightIBMCorporation2008

http://ss.hnu.cn/unix/ebook/aixbasics1.html

133/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
Figure713.viOptions

AU1310.0

Notes:
Changingvibehavior
vihasmanymodesofoperation.Someofthesewillaffectthewaytextispresented,
whileotherswillmakeeditingeasierfornoviceusers.Herearesomeexamples:
:setall

Displayallsettings.

:set

Displaysettingsdifferentthanthedefault.

:setautoindent Setsautoindenton.
:setnoautoindentTurnsautoindentmodeoff.
:setnumber
Enableslinenumbers.
:setnonumber

Turnslinenumbersoff.

:setlist

Displaysnonprintablecharacters.

:setnolist

Hidesnonprintablecharacters.

CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

719

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

:setshowmode

Showsthecurrentmodeofoperation.

:setnoshowmode Hidesmodeofoperation.
:settabstop=4

Setstabsto4characterjumps.

:setignorecase Ignorescasesensitivity.
:setnoignorecaseCasesensitive.
:setwrapmargin=5Setsthemarginforautomaticwordwrappingfromonelineto
next.Avalueof0turnsoffwordwrapping.

Optionsfile
Thefile.exrcwillbesearchedforinthecurrentdirectoryfirst.Iffound,thenitwillbe
readforsettingsasabove.
Ifno.exrcwasfoundinthecurrentdirectory,theHOMEdirectoryissearchednext.
Finally,thebuiltindefaultsareused.
.exrccontentsaresetoptions,butwithouttheinitialcolon(:).

http://ss.hnu.cn/unix/ebook/aixbasics1.html

134/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

720AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

CommandLineEditing

Usessameeditingkeysasvi

Cancorrectmistakes inthecurrentline

Useseditorkeystoedit/reenterpreviouslines

$setovi
Remember:

hjkl

CopyrightIBMCorporation2008

Figure714.CommandLineEditing

AU1310.0

Notes:
Editingthecommandline
Normally,youcanonlyeditthecommandlineusingthebackspacekey( <Ctrlh>)to
backupanderaseinputortheinterruptkey( <Ctrlx>).Thecommandlineediting
featureoftheKornshell allowsyoutousethesamekeysasthevieditortoeditthe
commandlineandcorrectmistakes.Manyoftheeditingfacilitiesoftheseeditorsare
available.

Enablingcommandlineediting
Toenablecommandrecall,youcanenterthecommandsetovi.Oncesetup,
previouscommandscanberecalledbyfirstpressingtheEsckeyandthenpressingthe
ktogoupaline.Thelistofcommandsisreadfromthe.sh_history file.
Thecommandlineeditorcanalsobesettousethecommandsfromtheemacseditor.It
issetthesamewayasvi:setoemacs
CopyrightIBMCorp.1995,2008

http://ss.hnu.cn/unix/ebook/aixbasics1.html

Unit7.TheviEditor

721

135/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Editingcommands
Youcantheneditthelineasyouwouldanylineoftextinavieditingsession.Only
singlelettercommandswillwork,includingthesearchcapabilities.

Executingcommands
Whenyouhaveeditedtheline,pressEnter,anditwillbeprocessedbytheshell.

Disablingcommandlineediting
Toturnoffthecommandrecallfacilityenter$set+ovi.Precedinganyoftheflags
witha+(plus)ratherthana(minus)turnsofftheoption.

722AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

viEditors
http://ss.hnu.cn/unix/ebook/aixbasics1.html

136/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

vi

Fullscreen,fullfunctioneditor

view

Readonlyformofvi,changescannotbe
savedunlessoverriddenwithaforce(!)

vedit

Beginnersversionof vi,showmodeison
bydefault

ex,ed

Subsetofviworkinginlinemode,can
accessthescreeneditingcapabilitiesofvi

edit

Simpleformofex
CopyrightIBMCorporation2008

AU1310.0

Figure715.vi Editors

Notes:
Introduction
emacsisanotherpopularUNIXeditorbutisnotstandardacrossallUNIXplatforms.

CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

723

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Checkpoint
1. Whenusingthevieditor,whatarethetwomodesofoperation?
2. Whileusingvi,howdoyougettocommandmode?

3. Whichofthefollowingcouldyouusetoenterintext?
a
x
i

http://ss.hnu.cn/unix/ebook/aixbasics1.html

137/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

dd

4. Whileincommandmode,pressingtheukeyrepeatedlywill"undo"all
previouslyenteredcommands.TrueorFalse?
5. vicanbeusedtogloballychangethefirstoccurrenceofapatternon
everylinewithagivenpattern.TrueorFalse?
CopyrightIBMCorporation2008

Figure716.Checkpoint

AU1310.0

Notes:

724AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Exercise: viEditor

CopyrightIBMCorporation2008

Figure717.Exercise:vi Editor

http://ss.hnu.cn/unix/ebook/aixbasics1.html

AU1310.0

138/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Notes:
Aftercompletingthelab,youshouldbeableto:
Createandeditfilesusingthevieditor
Invokecommandlineediting

CopyrightIBMCorp.1995,2008

Unit7.TheviEditor

725

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

UnitSummary
The vicommandstartsafullscreen editor.
vihastwomodesofoperation:textinputmode and
commandmode .
vimakesacopy ofthefileyouareeditinginaneditbuffer.
Thecontentsarenotchanged untilyousave thechanges.
Subcommandswiththe :, /, ?,or!readinput fromaline
displayedatthebottomofthescreen .

CopyrightIBMCorporation2008

Figure718.UnitSummary

AU1310.0

Notes:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

139/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

726AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Unit8.ShellBasics
WhatThisUnitIsAbout
Thisunitintroducesthemajorfunctionsavailablewithinshells.

WhatYouShouldBeAbletoDo
Aftercompletingthisunit,studentsshouldbeableto:
Usewildcardstoaccessfileswithsimilarnames
Useredirectionandpipestocontroltheinputandoutputof
processes
Uselinecontinuationinordertoenterlongcommandlines
Groupcommandsinordertocontroltheirexecution

HowYouWillCheckYourProgress
Accountability:
Studentactivity
Checkpointquestions
Exercise

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

81

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

140/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

StudentNotebook

UnitObjectives
Aftercompletingthisunit,youshouldbeableto:
Use wildcards toaccessfileswithsimilarnames
Use redirection and pipes tocontroltheinput and output of
processes
Use linecontinuation toentercommandsthatspanthe
commandline
Groupcommands inordertocontroltheirexecution

CopyrightIBMCorporation2008

Figure81.UnitObjectives

AU1310.0

Notes:

82AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

TheShell

http://ss.hnu.cn/unix/ebook/aixbasics1.html

141/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Korn(ksh) orBourne(bsh)orC(csh)

Userinterface toAIX

Commandinterpreter

Enablesmultipletasks

Comprehensive programminglanguage

CopyrightIBMCorporation2008

Figure82.TheShell

AU1310.0

Notes:
Shellfeatures
Theshellistheprimaryinterfacebetweentheuserandtheoperatingsystem.The
standardshellinAIXistheKornshell.
Theshellinterpretsusercommandstostartapplicationsandusethesystemutilitiesto
manageuserdata.
Theshellenablesmultipleprocessestoberunninginthebackgroundsimultaneouslyto
theforegroundprocesswithwhichtheuserisinteracting.
Theshellcanbeusedasacomprehensiveprogramminglanguagebycombining
sequencesofcommandswiththevariablesandflowcontrolfacilitiesprovidedbythe
shell.

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

83

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

MetacharactersandWildcards

Metacharacters arecharactersthattheshellinterpretsashavinga
specialmeaning .

Examples:
< > | ! * ? [ ] $ \"''

Wildcards areasubsetofmetacharactersthatareusedtosearch
for and matchfilepatterns .

http://ss.hnu.cn/unix/ebook/aixbasics1.html

142/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Examples:
* ? ! [ ] [ ]

CopyrightIBMCorporation2008

Figure83.MetacharactersandWildcards

AU1310.0

Notes:
Metacharacters
Wewillintroducethemeaningofeachofthemetacharactersduringthecourseofthis
unit.
Becausethemetacharactershavespecialmeaningtotheshell,theyshouldnot
normallybeusedasanypartofafilename.
Thesymbolcanusuallybeusedinafilenameprovideditisnotthefirstcharacter.
Forexample,ifwehadafilecalledlthenissuingthecommandlslwouldgiveyou
alonglistingofthecurrentdirectorybecausethelscommandwouldthinkthelwasan
optionratherthanlbeingafilenameargument.SomeAIXcommandsprovide
facilitiestoovercomethisproblem.

Availablemetacharacters
!" $ % ^& * ( ) { } [ ] # ~' < > / ?' \ |
84AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

FileNameSubstitution(1of2)
Wildcards:

Onecharactercompare:

home

$lsne?
net
new
$rm?e?
few
net

team01

new

Multiplecharactercompare:
$cpn*
nenet

/tmp
newnest

$qprt *w
new
few
$echotest1*
test1test1.2

test1.3

test1
test1.2
test1.3
myfile
ne
net
new
nest
few

CopyrightIBMCorporation2008

Figure84.FileNameSubstitution(1of2)

AU1310.0

Notes:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

143/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Wildcards
Thewildcard?isexpandedbytheshelltomatchfromanysinglecharacterinafile
name.Theexceptionisthatthe?willnotmatchadot .asthefirstcharacterofafile
name(forexample,inahiddenfile).
Thewildcard*isexpandedbytheshelltomatchzerotoanynumberofcharactersina
filename.Thesingle*willbeexpandedtomeanallfilesinthecurrentdirectoryexcept
thosebeginningwithadot.Bewareofthecommandrm*whichcouldcauseserious
damageremovingallfiles.
Sincetheshellisinterpretingthewildcardmetacharactersandalwayssubstitutes
filenames,filenamesubstitutionisonlyusefulforcommandsthatusefilenameoption
valuesorarguments.Forexample,thecommand:mailteam*wouldnotexpandtoa
listofusersstartingwithteam.

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

85

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

FileNameSubstitution(2of2)
InclusiveLists: [ ] !

[]
/

$lsne[stw]
netnew
home
$rm[fghjdn]e[tw]
fewnetnew
$ls*[15]
test1test1.2test1.3
$qprt[!tn]*
myfilefew
$cat?[!y]*[25]
test1.2test1.3

team01
test1
test1.2
test1.3
myfile
ne
net
new
nest
few

CopyrightIBMCorporation2008

Figure85.FileNameSubstitution(2of2)

AU1310.0

Notes:
Inclusionlists
Thepositionheldbythebracketsandtheircontentswillbematchedtoasingle
characterinthefilename.Thatcharacterwilleitherbeamemberofalistorrange,or
anycharacterwhichisnotamemberofthatlistorrangeifthe!characterisusedatthe
startoftheinclusionlist.

Examples
Theexamplesonthevisualdothefollowing:
http://ss.hnu.cn/unix/ebook/aixbasics1.html

144/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Thefirstexamplewilllistallthreeletterfileswhichbeginwiththelettersn
eandhave
asthelastlettereithersortorw
ThesecondexamplewillremoveanyfilethatbeginswithONEofthecharacters
fromthefirstsetofbrackets,hasthemiddleletteraseandendswitheithertorw
Thethirdexamplewilllistallfilesthatendwitheither1,2,3,4,or5
86AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Thefourthexamplewillprintallfilesthatdonotbeginwiththeletterstorn
Thefinalexamplewilldisplaythecontentsofanyfilethathasthefirstcharacteras
anything,thesecondlettermustnotbey,zeroormorecharacterscanthenfollow,
withthelastcharacterbeingonefromtherange2through5

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

87

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

145/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

StudentNotebook

TheStandardFiles
standardin(0)

cmd

standardout(1)

standarderror(2)

CopyrightIBMCorporation2008

Figure86.TheStandardFiles

AU1310.0

Notes:
Commandredirection
Theshellistheprimaryinterfacebetweentheuserandtheoperatingsystem.The
standardshellinAIXistheKornshell.
Threefilesareautomaticallyopenedforeachprocessinthesystem.Thesefilesare
referredtoasstandardinput,standardoutput,andstandarderror.
Whenanapplicationworkswithafile,itopensthefileusingthepathtothefile,butonce
thefileisopentheapplicationusesanumericalidentifier,calledafiledescriptor,to
identifywhichfiletoreadfromorwriteto.Thenumbersshownonthefoilarethe
standardfiledescriptorsfor:STDIN(0),STDOUT(1),andSTDERR(2).
Standardinput,sometimesabbreviatedtostdiniswhereacommandexpectstofind
itsinput,usuallythekeyboard.
Standardout( stdout)andstandarderror( stderr)arewherethecommandexpectsto
putitsoutput,usuallythescreen.Thesedefaultscanbechangedusingredirection.
88AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

FileDescriptors
Threedescriptors areassignedbytheshellwhentheprogramstarts:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

146/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Standardin:

<

Standardout:

>

Standarderror:

2>

CopyrightIBMCorporation2008

Figure87.FileDescriptors

AU1310.0

Notes:
AIXfiledescriptors
Afiledescriptornumberiswhataprogramuseswhenitneedstoidentifyafilewhichit
willbereadfromorwritingto.Thefiledescriptorswilldifferdependingonthecommand
orutilitythatiscurrentlyrunning.EachAIXcommandopensitsownsetoffile
descriptorsinordertokeeptrackofthedatafiles,input,output,anderrormessages.

Specialfiles
RememberthatinAIX,notallfilenamesrefertorealdatafiles.Somefilesmaybe
specialfileswhichinrealityareapointertosomeofthedevicesonthesystem.An
examplewouldbe/dev/tty0 .

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

89

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

InputRedirection

Defaultstandardinput

$mailteam01
Subject:Letter
Thisisaletter.
<ctrld>
Cc:
$

Redirectinputfromafile:<

http://ss.hnu.cn/unix/ebook/aixbasics1.html

147/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

$mailteam01<letter

CopyrightIBMCorporation2008

Figure88.InputRedirection

AU1310.0

Notes:
Redirection
Intheredirectionexample,thefileletter canbecreatedusinganeditororword
processingapplication.Itisthenusedasstandardinputtothemailprogramrather
thantypingfromthekeyboard.Thiswouldmakeitmucheasiertoformattheletteror
correctanytypingmistakes.
Withredirectionandthemailcommand,youwillnotgetthenormalpromptsfor
Subject:orCc:.Youmustusethefollowingsyntax:
mailsMySubjectcuser1,user2recipient
Thesymbol<tellsmailtotakeinputfromthefileinsteadofthekeyboard.
Themailprogramhandlesstandardoutdifferentlythanothercommands.

810AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

OutputRedirection

Defaultstandardoutput:

$ls
file1

file2file3

Redirectoutputfromafile:>

$ls>ls.out
$

Redirectingandappendingoutputtoafile:>>

$who
$

>>

whos.there

CopyrightIBMCorporation2008

Figure89.OutputRedirection

AU1310.0

Notes:
Standardoutputredirection
http://ss.hnu.cn/unix/ebook/aixbasics1.html

148/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

Redirectionallowsstandardoutputtogotosomewhereotherthanthescreen(default).
Intheexample,standardoutputhasbeenredirectedtogotothefilenamedls.out .
Thefiledescriptortableinthisexamplewillholdthefollowingvalues:
STDIN
ls.out
STDERR

0(unchanged)
1(changed)
2(unchanged)

Usingordinaryredirectioncanoverwriteanexistingfile.Toavoidthis,use>> (nospace
betweenthem)toappendtheoutputtoanexistingfile.
Thefiledescriptorsfortheappendexamplewillbeasfollows:
STDIN
whos.there
STDERR

0(unchanged)
1(changed)
2(unchanged)
CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

811

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

CreatingaFilewithcat

Whilenormallyusedtolistthecontentsoffiles,usingcatwith
redirectioncanbeusedtocreateafile:
$ls
letteracctfilefile1
$catfile1
Thisisatestfile.
Thefilehas2lines.
$

Using redirection :
$cat>newfile
Thisisline1ofthefile.
Thisisthe2ndline.
Andthelast.
<ctrld>
$ls
letteracctfilefile1

newfile

CopyrightIBMCorporation2008

AU1310.0

Figure810.CreatingaFilewithcat .

Notes:
Otherusesforcat
Youalreadylearnedinanearlieractivitythatyoucancreatefileswiththecat
command.
Forthecat>newfileexample,thefiledescriptorswillholdthefollowinginformation:
0(unchanged)
1(changed)
2(unchanged)

http://ss.hnu.cn/unix/ebook/aixbasics1.html

STDIN
newfile
STDERR

149/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

812AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Activity:ReviewShellBasics
1.

Whichfilesarelistedwhenthefollowingcommandsareexecuted?

$ls/home/team01/*.?
$ls/tmp/[azAZ]*.[09]
2.

True or False :Thecommand"ls*"listsallfilesinadirectory.

3.

Writedownthefiledescriptors forthefollowingcommand:

$wcl<file1>/tmp/lines
Standardinput:
Standardoutput:
Standarderror:
4.

Youwanttoappendfiletestfile1 tofilereport99 .Whichcommandiscorrect?

ocatreport99<testfile1
ocattestfile1>report99
ocattestfile1report99
ocattestfile1>>report99

CopyrightIBMCorporation2008

Figure811.Activity:ReviewShellBasics

AU1310.0

Notes:
Activity
Pleaseanswerthequestionsinthevisual.

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

813

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

150/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

ErrorRedirection

Defaultstandarderror:
$catfileafileb
Thisisoutputfromfilea.
cat:cannotopenfileb

Redirectingerroroutputtoafile:2>(Toappend:2>>)
$catfileafileb2>errfile
Thisisoutputfromfilea
$caterrfile
cat:cannotopenfileb
$catfileafileb2>/dev/null
Thisisoutputfromfilea

CopyrightIBMCorporation2008

Figure812.ErrorRedirection

AU1310.0

Notes:
STDERRredirection
Errormessagesfromcommandswouldnormallybesenttothescreen.Thiscanbe
changedbyredirectingtheSTDERRtoafile.
Whenredirectingoutput,therecanbenospacesbetweenthe2andthe>.
Thefiledescriptortableforthefirsterrorredirectionexamplewillcontainthefollowing:
STDIN
STDOUT
errfile

0(unchanged)
1(unchanged)
2(changed)
andforthesecond:

STDIN
STDOUT
/dev/null

0(unchanged)
1(unchanged)
2(changed)
814AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty Specialfile
Thespecialfile/dev/null isabottomlesspitwhereyoucanredirectunwanteddata.All
datasentthereisjustthrownaway.
/dev/null isaspecialfile.Ithasauniquepropertyasitisalwaysempty.Itiscommonly
referredtoasthebitbucket.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

151/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

815

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

CombinedRedirection

Combinedredirects:
$command>outfile2>errfile<infile
$command>>appendfile2>>errfile<infile

Associationexamples:

Redirectstandarderrortostandardout:
$command>outfile2>&1

CAUTION:ThisisNOTthesameasabove
http://ss.hnu.cn/unix/ebook/aixbasics1.html

152/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

$command2>&1>outfile
CopyrightIBMCorporation2008

Figure813.CombinedRedirection

AU1310.0

Notes:
Combinedredirectionexample
Onemayredirectmultiplefiledescriptorsonasinglecommand.Normallytheorderin
whichyoudotheredirectionsisnotimportant,unlessyouareusingassociation.

Associationexample
Inthefirstexample,filedescriptor1isassociatedwiththefilespecified,outfile .Then
theexampleassociatesdescriptor2withthefileassociatedwithfiledescriptor1,
outfile .
Iftheorderoftheredirectionisreversedasinthesecondexample,thenfiledescriptor2
wouldbeassociatedwiththeterminal(standardout)andfiledescriptor1wouldbe
associatedwiththefilespecifiedoutfile .

816AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Orderofredirectioninassociations
Withtheassociationexamples,theorderinwhichredirectionsarespecifiedis
significant.Forassociation,hereisanexampleofls:
lsl/>./list.file2>&1
0(unchanged)
1(changed)
2(changed)

STDIN
./list.file
./list.file

Andhereisanexampleofhownottodoassociation:
lsl/2>&1>./list.file
0(unchanged)
1(changed)
2(unchanged)

STDIN
./list.file
STDOUT

Inthesecondassociationexample,theerrorsareredirectedtothesameplaceas
standardout.Butstandardoutatthispointhasnotbeenredirectedyet,sothedefault
valuewillbeusedwhichisthescreen.So,theerrormessageswillberedirectedtothe
screen.Rememberthatbydefaulterrormessagesaresenttothescreen.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

153/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

817

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Pipes
Asequenceofoneormorecommandsseparatedbyaverticalbar" | " iscalledapipe .The
standardoutput ofeachcommandbecomesthestandardinput ofthenextcommand.

$who|wcl
4

Thisisthesameas:

$who>tempfile
$wcltempfile
4
tempfile
$rmtempfile

CopyrightIBMCorporation2008

Figure814.Pipes

AU1310.0

Notes:
Commandpipes
Twoormorecommandscanbeseparatedbyapipeonasinglecommandline.The
requirementisthatanycommandtotheleftofapipemustsendoutputtostandard
output.Anycommandtotherightofthepipemusttakeitsinputfromstandardinput.
Theexampleonthevisualshowsthattheoutputofwhoispassedasinputtowcl,
whichgivesusthenumberofactiveusersonthesystem.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

154/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

818AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Filters
A filter isacommandthatreadsfromstandardin , transforms
theinput insomeway,andwritestostandardout .
Example:
lsl|grep"^d"|wcl

Longlistingofallfiles:
rwxrxrx...file1
drwxrxr...dir1
rwxrr...file2

Findalllinesthatbegin
witha"d":
drwxrxr...dir1

Countalllines
(directories)

CopyrightIBMCorporation2008

Figure815.Filters

AU1310.0

Notes:
Filteruses
Acommandisreferredtoasafilterifitcanreaditsinputfromstandardinput,alteritin
someway,andwriteitsoutputtostandardoutput.Afiltercanbeusedasan
intermediatecommandbetweenpipes.
Afilteriscommonlyusedwithastringofpipedcommands,asintheexampleabove.
Thelslcommandlistsallthefilesinthecurrentdirectoryandthenpipesthis
informationtothegrepcommand.Thegrepcommandwillbecoveredinmoredetail
laterinthecourse,butinthisexample,thegrepcommandisusedtofindalllines
beginningwithad(directories).Theoutputofthegrepcommandisthenpipedtothe
wclcommand.Theresultisthatthecommandiscountingthenumberofdirectories.
Inthisexample,thegrepcommandisactingasafilter.

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

819

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

155/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

SplitOutputs
The teecommandreadsstandardinputandsendsthedatato
bothstandardoutputandafile.
ls|tee/tmp/ls.save|wcl

tee
cow
fox
ox

wc

ls

l
/tmp/ls.save
cow
fox
ox

CopyrightIBMCorporation2008

Figure816.SplitOutputs

AU1310.0

Notes:
teecommand
Thetee commandisafilterthatcanbeusedtocaptureasnapshotofinformationgoing
throughapipe.tee putsacopyofthedatainafileaswellaspassingittostandard
outputtobeusedbythenextcommand.tee doesnotalterthedata.

820AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

CommandGrouping
Multiplecommandscanbeenteredonthesameline,separatedbya
semicolon"":

$lsR>outfileexit

http://ss.hnu.cn/unix/ebook/aixbasics1.html

156/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

isequivalenttoentering:

$lsR>outfile
$exit

CopyrightIBMCorporation2008

Figure817.CommandGrouping

AU1310.0

Notes:
Groupingcommands
Placingmultiplecommandsseparatedbya onasinglelineproducesthesameresult
asenteringeachcommandonaseparatecommandline.

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

821

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

LineContinuation
Thebackslash(\)followedbyanewlinecharactercanbeusedto
continueacommand ona separateline .
A secondarypromptcharacter ">"isissuedbytheshelltoindicateline
continuation .

$cat/home/mydir/mysubdir/mydata\

>/home/yourdir/yoursubdir/yourdata

http://ss.hnu.cn/unix/ebook/aixbasics1.html

157/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html
CopyrightIBMCorporation2008

Figure818.LineContinuation

AU1310.0

Notes:
Continuingthecommandlineinshell
TheEnterkeyprecededbyabackslash( \<Enter>)canbeusedtocontinuea
commandonaseparateline.
Donotconfusethecontinuationprompt>withtheredirectioncharacter>.The
secondarypromptwillnotformpartofthecompletedcommandline.Ifyourequirea
redirectioncharacteryoumusttypeitexplicitly.

822AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Checkpoint(1of2)
1. Whatwillthefollowingcommandmatch?
$ls ???[!az]*[09]t

2. Forquestions24,indicatewherethestandardinput,
standardoutputandstandarderrorwillgo.
$catfile1
standardinput(0):
standardoutput(1):
standarderror(2):

3. $mailtim

<letter

standardinput(0):
standardoutput(1):
standarderror(2):
CopyrightIBMCorporation2008

Figure819.Checkpoint(1of2)

AU1310.0

Notes:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

158/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

823

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

Checkpoint(2of2)
4. $cat.profile>newprofile2>1
standardinput(0):
standardoutput(1):
standarderror(2):

Forquestions5,6,and7,createcommandlinestodisplaythe
contentoffilea using catandthenperformthefollowing:
5. Placetheoutputofthecommandinfileb andtheerrorsin
filec.
6. Placetheoutputofthecommandinfileb andassociateany
errorswiththeoutputinfileb .
7. Placetheoutputinfileb anddiscardanyerrormessages.
(Donotdisplayorstoreerrormessages.)
CopyrightIBMCorporation2008

Figure820.Checkpoint(2of2)

AU1310.0

Notes:

http://ss.hnu.cn/unix/ebook/aixbasics1.html

159/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

824AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

V3.1
StudentNotebook

Uempty

Exercise:ShellBasics

CopyrightIBMCorporation2008

Figure821.Exercise:ShellBasics

AU1310.0

Notes:
Aftercompletingthisexercise,youwillbeableto:
Usewildcardsforfilenameexpansion
Redirectstandardinput,standardoutput,andstandarderror
Usepipes,commandgrouping,andlinecontinuation

CopyrightIBMCorp.1995,2008

Unit8.ShellBasics

825

Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

StudentNotebook

http://ss.hnu.cn/unix/ebook/aixbasics1.html

160/161

11/25/2014

ss.hnu.cn/unix/ebook/aixbasics1.html

UnitSummary
Wildcards , * and ? ,provideaconvenientwayforspecifying
multiplefilesordirectorynames.
The wildcardnotation [] islikeusingthe? butitallowsyouto
choosespecificcharacterstobematched.
Threefilesautomaticallyopenedforredirection arestandard
in,standardout,andstandarderror.
I/Oredirection altersthedefaultinputsourceoroutput
destinationofacommand.
A pipe passestheoutputofonecommanddirectlytotheinput
ofanothercommand.
A filter takesinputfromstandardin,transformsit,andsends
theoutputtostandardout.
tee takesinputandroutesittotwoplaces,standardoutanda
file.
CopyrightIBMCorporation2008

Figure822.UnitSummary

AU1310.0

Notes:

826AIX6Basics

CopyrightIBMCorp.1995,2008
Coursematerialsmaynotbereproducedinwholeorinpart
withoutthepriorwrittenpermissionofIBM.

http://ss.hnu.cn/unix/ebook/aixbasics1.html

161/161

You might also like