Using HP-UX

236
Using HP-UX HP 9000 Computers E0997 HP Part No. B2355-90164 September 1997 Printed in: USA

Transcript of Using HP-UX

Page 1: Using HP-UX

Using HP-UX

HP 9000 Computers

E0997

HP Part No. B2355-90164

September 1997

Printed in: USA

Page 2: Using HP-UX

2

Legal NoticesThe information contained in this document is subject to change withoutnotice.

Hewlett-Packard makes no warranty of any kind with regard to thismanual, including, but not limited to, the implied warranties ofmerchantability and fitness for a particular purpose. Hewlett-Packardshall not be liable for errors contained herein or direct, indirect, special,incidental or consequential damages in connection with the furnishing,performance, or use of this material.

Warranty

A copy of the specific warranty terms applicable to your Hewlett-Packardproduct and replacement parts can be obtained from your local Sales andService Office.

Restricted Rights Legend

Use, duplication, or disclosure by the U.S. Government is subject torestrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights inTechnical Data and Computer Software clause in DFARS 252.227-7013.

Hewlett-Packard Company 3000 Hanover StreetPalo Alto, CA 94304 U.S.A.

Rights for non-DOD U.S. Government Departments and Agencies are asset forth in FAR 52.227-19(c)(1,2).

All rights reserved.

Trademark Acknowledgement

UNIX is a registered trademark in the United States and othercountries, licensed exclusively through X/Open Company Limited.

© Copyright 1997 and 1983-1996 Hewlett-Packard Company andCopyright © 1980, 1984, 1986 UNIX System Laboratories, Inc.Reproduction, adaptation, or translation without prior writtenpermission is prohibited, except as allowed under the copyright laws.

Page 3: Using HP-UX

Contents

3

Printing History. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15

How to Use this Guide. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16Typographic Conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17

1. Getting Started

Overview of Your System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20Multi-User Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21Trusted Systems. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22

Logging In and Out of HP-UX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23Logging In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23Using HP-UX Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25Logging Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26

Modifying System Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27

Changing Your Password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28

Finding Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29Manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29Online Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30Manual Reference Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30

2. Working with Files and Directories

Creating a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34

Listing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35

Naming Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36Guidelines for File Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36Invisible File Names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37

Viewing and Printing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38Viewing a File with more . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38Displaying the First and Last Lines of a File . . . . . . . . . . . . . . . . . . . .39

Page 4: Using HP-UX

4

Contents

Printing a File with lp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Renaming, Copying, and Removing Files . . . . . . . . . . . . . . . . . . . . . . . . 41Renaming Files with mv. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Copying Files with cp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42Removing Files with rm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Comparing the Contents of Two Files. . . . . . . . . . . . . . . . . . . . . . . . . . . 43

Joining Two Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

Understanding a Directory Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Determining Your Location in an HP-UX Directory Hierarchy. . . . . . . 48

Specifying Files and Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Absolute Path Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Relative Path Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

Creating Directories. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

Changing Your Current Directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

Moving and Copying Files between Directories . . . . . . . . . . . . . . . . . . . 58Moving Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58Copying Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

Copying Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

Removing Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61Removing a Directory with rmdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61Removing Everything with rm -rf . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

File Name Shorthand: Wildcard Characters . . . . . . . . . . . . . . . . . . . . . 63The * Wildcard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63The ? Wildcard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Using the * Wildcard Character with mv, cp, and rm. . . . . . . . . . . . . 64

Searching for Text Patterns using grep . . . . . . . . . . . . . . . . . . . . . . . . . 65Searching a File for a Text String . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

Page 5: Using HP-UX

Contents

5

Searching Multiple Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66

Searching for Files using find . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67Finding Files that Match a Pattern. . . . . . . . . . . . . . . . . . . . . . . . . . . .67Finding Files that are Newer than a Certain File . . . . . . . . . . . . . . . .67Running Commands on Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .68Using Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .68

Chapter Command Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69

3. Using Your Shell

Understanding Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72Examples Using Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72Examples Using Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73Enclosing Arguments in Quotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73Running Multiple Commands on the Same Command Line . . . . . . . .73

Understanding Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74How Processes are Created . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74Stopping a Process with kill. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75

Understanding Standard Input, Standard Output, and Standard Error .76

Writing Standard Output to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . .77Using Files for Standard Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79Redirecting Both Standard Input and Standard Output . . . . . . . . . . .81Piping Command Output and Input . . . . . . . . . . . . . . . . . . . . . . . . . . .83

Shell Features: Determining and Changing Your Shell . . . . . . . . . . . . .86Determining Your Login Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88Temporarily Changing Your Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89Permanently Changing Your Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . .89

Editing the Command Line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90Using vi Line Editing Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90

Page 6: Using HP-UX

6

Contents

An Example of Line Editing with the vi Command Set . . . . . . . . . . . 91

Recalling Previous Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92For More Information… . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

Setting the Login Environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94The login Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

Using Login Scripts to Set the System Environment . . . . . . . . . . . . . . 97Why Use Login Scripts? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97A Summary of Login Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

Setting and Referencing Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99Assigning Values to Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99Referencing the Values of Variables (Parameter Substitution) . . . . 100

Finding Commands with Search Paths. . . . . . . . . . . . . . . . . . . . . . . . . 101PATH Variable Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101Changing PATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102Setting PATH as an Environment Variable. . . . . . . . . . . . . . . . . . . . 103

Setting Terminal Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104Selecting a Value for the TERM Variable . . . . . . . . . . . . . . . . . . . . . 104Setting TERM with the tset Command . . . . . . . . . . . . . . . . . . . . . . . 105

Chapter Command Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

4. Using the vi Editor

Starting the vi Editor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110Command Mode and Text Entry Mode in vi . . . . . . . . . . . . . . . . . . . 111If You Make Mistakes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

Entering and Deleting Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

Positioning the Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

Scrolling through Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

Page 7: Using HP-UX

Contents

7

Finding Text Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115Searching for Special Occurrences . . . . . . . . . . . . . . . . . . . . . . . . . . .116

Replacing Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117Substituting Characters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117

Saving Your Work and Exiting vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .118

Using Options to Change Your vi Environment. . . . . . . . . . . . . . . . . . .119

Making Your vi Environment Permanent . . . . . . . . . . . . . . . . . . . . . . .121An Example of Changing Your .exrc File . . . . . . . . . . . . . . . . . . . . . .122For More Information… . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .122

Chapter Command Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123

5. Using Electronic Mail

Starting the elm Mailer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126

Understanding the Main Screen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127

Entering elm Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129

Reading Your Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .130

Sending Mail to Users on Your System . . . . . . . . . . . . . . . . . . . . . . . . .132

Sending Mail to Users on Other Systems . . . . . . . . . . . . . . . . . . . . . . .134Mail Syntax when Mailing to Other Systems. . . . . . . . . . . . . . . . . . .135

Using Mail Aliases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .136Understanding Mail Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .136Creating Mail Aliases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .137Listing and Deleting Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .138

Replying to Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .139

Forwarding Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141

Saving Messages to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .143

Page 8: Using HP-UX

8

Contents

Deleting Mail Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

Exiting the elm mailer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

Mailing a Directory and Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146Using Options for Packing Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

Customizing elm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148Using the Options Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148Changing the User Level of elm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

Chapter Command Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

6. Communicating over a Network

HP-UX Network Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154Remote File Systems: NFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

Using Global Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

Transferring Files Remotely with ftp . . . . . . . . . . . . . . . . . . . . . . . . . . 156Preparing to Use ftp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156Starting ftp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157Listing and Creating Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158Transferring Files from a Remote System. . . . . . . . . . . . . . . . . . . . . 159Transferring Files to a Remote System . . . . . . . . . . . . . . . . . . . . . . . 161Exiting ftp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

Copying Files Remotely with rcp. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163Preparing to Use rcp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163Copying Files to a Remote System. . . . . . . . . . . . . . . . . . . . . . . . . . . 165Copying Files from a Remote System . . . . . . . . . . . . . . . . . . . . . . . . 166Copying Directories to a Remote System. . . . . . . . . . . . . . . . . . . . . . 167Copying Directories from a Remote System . . . . . . . . . . . . . . . . . . . 168

Logging In to Another Computer with rlogin . . . . . . . . . . . . . . . . . . . . 169Preparing to Use rlogin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

Page 9: Using HP-UX

Contents

9

Logging In on a Remote System . . . . . . . . . . . . . . . . . . . . . . . . . . . . .170Logging Out and Exiting the Remote System . . . . . . . . . . . . . . . . . .170Temporarily Returning to Your Local System . . . . . . . . . . . . . . . . . .171

Running a Command Remotely with remsh . . . . . . . . . . . . . . . . . . . . .172Preparing to Use remsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .172Running a Command Remotely. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .173

Chapter Command Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174

7. Making Your System Secure

Security Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .178

Securing Your Terminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .179Guidelines for Securing Your Terminal. . . . . . . . . . . . . . . . . . . . . . . .179Working in an Audited Environment . . . . . . . . . . . . . . . . . . . . . . . . .179

Choosing a Secure Password. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .180What is a Secure Password? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .180Trusted System Passwords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .181Protecting Your Password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .182

Protecting Your Files and Directories. . . . . . . . . . . . . . . . . . . . . . . . . . .183Who Has Access? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .183What Kind of Access? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .183Displaying Access Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184Guidelines for Access to Sensitive Files . . . . . . . . . . . . . . . . . . . . . . .187For More Information… . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .187

Changing File or Directory Ownership . . . . . . . . . . . . . . . . . . . . . . . . .188

Changing Who Has Access to Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . .189Using chmod to Set File Permissions . . . . . . . . . . . . . . . . . . . . . . . . .189

Changing Who Has Access to Directories . . . . . . . . . . . . . . . . . . . . . . .191For More Information… . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .191

Page 10: Using HP-UX

10

Contents

Controlling Default Access Permissions . . . . . . . . . . . . . . . . . . . . . . . . 192For More Information… . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

Privileged Groups. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195

Trusted System Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196Access Control Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197

Obtaining Software Security Patches . . . . . . . . . . . . . . . . . . . . . . . . . . 200

Chapter Command Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

A. HP-UX Quick Reference

How to use this Reference:. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203

B. Doing Advanced HP-UX Tasks

For advanced users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

C. Scheduling Commands

Running Commands at Preset Times . . . . . . . . . . . . . . . . . . . . . . . . . . 211Prerequisites for Using at and crontab . . . . . . . . . . . . . . . . . . . . . . . 211Running Commands Using at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212Submitting Batch Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212Running Commands Using crontab . . . . . . . . . . . . . . . . . . . . . . . . . . 213

D. The Key Shell

Using the Key Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215Using the Key Shell Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215Example: Entering a Command with the Key Shell . . . . . . . . . . . . . 216Customizing Your Key Shell Softkeys . . . . . . . . . . . . . . . . . . . . . . . . 217Summary of Key Shell Procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . 218

Glossary

Page 11: Using HP-UX

Figures

11

Figure 1-1 . Type your user name at the login prompt.. . . . . . . . . . . . . .23

Figure 2-1 . A Typical HP-UX Directory Structure . . . . . . . . . . . . . . . . .46

Figure 2-2 . A System Directory Structure . . . . . . . . . . . . . . . . . . . . . . .47

Figure 2-3 . The HP-UX Directory Structure. . . . . . . . . . . . . . . . . . . . . .48

Figure 2-4 . Leslie's Home Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . .49

Figure 2-5 . Absolute Path Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51

Figure 2-6 . Relative Path Names from /home/engineers/leslie . . . . . . .53

Figure 2-7 . Creating the “projects” Directory . . . . . . . . . . . . . . . . . . . . .54

Figure 2-8 . Structure after Creating New Directories . . . . . . . . . . . . . .55

Figure 2-9 . Effect of Various “cd” Commands . . . . . . . . . . . . . . . . . . . . .57

Figure 2-10 . The “projects” Directory Structure . . . . . . . . . . . . . . . . . . .61

Figure 3-1 . Standard Input, Standard Output, and Standard Error . .76

Figure 3-2 . Standard Input, Output, and Error When Output IsRedirected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .77

Figure 3-3 . Standard Input, Output, and Error When Input IsRedirected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79

Figure 3-4 . Redirecting Both Input and Output . . . . . . . . . . . . . . . . . . .81

Figure 3-5 . Standard Input and Output with Pipes and tee Command 84

Figure 5-1 . The elm mailer lets you send and receive messages. . . . .127

Figure 5-2 . Elm lists your mail messages. . . . . . . . . . . . . . . . . . . . . . .130

Figure 5-3 . An example message. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131

Figure 5-4 . An example message. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .133

Figure 5-5 . Example host names on a network. . . . . . . . . . . . . . . . . . .134

Figure 5-6 . The host name is circled.. . . . . . . . . . . . . . . . . . . . . . . . . . .134

Page 12: Using HP-UX

12

Figures

Figure 5-7 . Messages are marked with a “D” for deletion. . . . . . . . . . 144

Figure 5-8 . You can configure elm using the options editor. . . . . . . . . 148

Figure 6-1 . Use ftp to get files from remote systems. . . . . . . . . . . . . . 160

Figure 6-2 . Use ftp to put files on remote systems. . . . . . . . . . . . . . . 162

Figure D-1 . Key Shell Softkey Display. . . . . . . . . . . . . . . . . . . . . . . . . 215

Figure D-2 . Options Displayed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216

Figure D-3 . Required Options Requested . . . . . . . . . . . . . . . . . . . . . . 216

Figure D-4 . Optional HP-UX Commands Display. . . . . . . . . . . . . . . . 216

Page 13: Using HP-UX

Tables

13

Table 3-1. Comparison of Shell Features . . . . . . . . . . . . . . . . . . . . . . . . .87

Table 3-2. Shell File Names and Default Prompts . . . . . . . . . . . . . . . . .88

Table 3-3. Shells and Their Login Scripts . . . . . . . . . . . . . . . . . . . . . . . .98

Table 4-1. Editor Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .120

Table 5-1. Elm Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .151

Table 6-1. Networking Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174

Table 7-1. A Comparison of Permissions for Directories and Files. . . .183

Table B-1. Advanced HP-UX Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . .207

Page 14: Using HP-UX

14

Tables

Page 15: Using HP-UX

15

About this Manual

Printing HistoryThe printing date will change when a new edition is printed. Minorchanges may be made at reprint without changing the printing date. Themanual part number will change when extensive changes are made.

Manual updates may be issued between editions to correct errors ordocument product changes. To ensure that you receive these updates ornew editions, see your HP sales representative for details.

August 1992…Edition 1…B2910-90001. This edition incorporatesmaterial from A Beginner's Guide to HP-UX, Edition E0191, with theaddition of updated material for HP-UX 9.0, HP VUE, the SystemAdministration Manager, and Instant Ignition. This manual applies toHP 9000 Series 300, 400, and 700 computers.

January 1995…Edition 2…A1700-90014. This edition includesinformation covering the 10.0 release of HP-UX. References to HP VUEhave been removed because HP VUE information is contained in UsingYour HP Workstation and the HP Visual User Environment 3.0 User'sGuide. This manual applies to HP 9000 Series 800 computers.

September 1997…Edition 3…B2355-90164. This edition includesinformation covering the 11.0 release of HP-UX for HP 9000 computers.

Page 16: Using HP-UX

16

How to Use this GuideThis guide covers everything you need to know to begin using your newHewlett-Packard computer. It provides step-by-step instructions for basictasks such as copying files, printing documents, and sending electronicmail.

This guide contains the following information:

• Chapter 1, Getting Started provides an overview of your system andexplains how to log in and log out.

• Chapter 2, Working with Files and Directories shows you how tocreate, view, print, and remove files; create and remove directories;and navigate between directories.

• Chapter 3, Using Your Shell explains how to use command syntax,redirect command input and output, and set your login environment.

• Chapter 4, Using the vi Editor describes how to create and edit textusing the vi editor.

• Chapter 5, Using Electronic Mail shows you how to send and receivemessages electronically.

• Chapter 6, Communicating over a Network describes how to use andcommunicate with remote systems.

• Chapter 7, Making Your System Secure covers system security andchanging file and directory permissions.

• Appendix A, HP-UX Quick Reference contains tables summarizinguseful HP-UX commands.

• Appendix B, Doing Advanced HP-UX Tasks provides pointers formore information about advanced and system administration tasksnot covered in this guide.

• Appendix C, Scheduling Commands describes ways to run programsautomatically at specified times.

• Appendix D, Using the Key Shell discusses an alternative commandintepreter (shell) that is very user friendly.

• Glossary explains common HP-UX terms.

Comments about this manual (no techical questions, please) can bedirected to: [email protected]. Please consult your HP service andsupport representative for technical support questions. Thanks.

Page 17: Using HP-UX

17

Typographic ConventionsThis guide uses the following typographic conventions:

Boldface Words defined for the first time appear in boldface. Forexample, an argument is the part of a command linethat indicates what file or directory the command is toact on.

Computer Computer font indicates literal items displayed by thecomputer. For example: file not found

User input Bold, computer text indicates literal items that youtype. For example: cd

Italics Manual titles and emphasized words appear in italics,as do values that you supply.

For example, in the command below you wouldsubstitute an actual directory name (such as mydir )for directory_name.

cd directory_name

Enter Text in a bold, sans serif font denotes a keyboard key. Anotation like CTRL+Q indicates that you should hold thecontrol key down, then press Q.

Softkey Select an on-screen item or a corresponding softkey. Forexample,

Help

shown at the bottom left side of the screen means thatpressing the softkey corresponding to that position onthe screen (f1) will cause a help screen to be displayed.

Page 18: Using HP-UX

18

Page 19: Using HP-UX

19

1 Getting Started

Welcome Your new Hewlett-Packard computer uses the HP-UX operating system.HP-UX is a versatile operating system that meets the computing needsof diverse groups of users. You can use HP-UX simply to runapplications, or you can develop your own applications in its richsoftware development environment. In addition, HP-UX offers powerfulsubsystems, such as electronic mail, windows, networking, and graphics.

Although some would say that the HP-UX operating system needs a“Survival Guide” more than a “Users Guide”, it’s really not that difficultto learn commands that will help you work more productively. Take yourtime and don’t worry if you don’t understand everything the first timeyou see it. Just keep in mind that most people don’t like typing, so manycommands and methods are shorter than you may think.

To do this ... See ...

Overview of your system page 20

Logging in and out of HP-UX page 23

Using HP-UX commands page 25

Changing system parameters page 27

Changing your password page 28

Finding information page 29

Page 20: Using HP-UX

20 Chapter 1

Getting StartedOverview of Your System

Overview of Your System

Installation Your system should be installed and ready to use. If you have not yetinstalled your system, please see the Hardware Installation Guide orOwner's Guide that came with it.

Also refer to the Owner's Guide for instructions on starting your system,performing initial configuration, and adding new user accounts.

User interfaces There are two common ways to access HP-UX.

• With a Graphical User Interface (GUI) such as HP’s CommonDesktop Environment (CDE) where you use a mouse and click onicons, or,

• With a textual user interface where you type simple commands into atext window.

This manual describes the latter method even though the next itembriefly describes the CDE.

CDE The HP Common Desktop Environment is a powerful graphicalenvironment that provides an interface to HP-UX. It has severalcomponents that help you use your system faster and more intuitively:

• Windows let you run more than one application at a time.

• Workspaces allow you to have multiple work areas.

• Icons let you directly manipulate files and applications.

• Front Panel controls and toolboxes for easy access to applications.

• Extensive online help, provided by the HP Help Manager.

• Easy customization for colors, fonts, and other aspects of theappearance and behavior of your workstation's interface.

• Multimedia (images and audio) applications for playing, recording,and editing audio, and capturing and viewing images.

For information about HP CDE, see the HP CDE User’s Guide.

Having now touched upon the easy way of working with HP-UX, we’ll goback down to the low-level textual methods which exist underneath theglossy user interface.

Page 21: Using HP-UX

Chapter 1 21

Getting StartedOverview of Your System

Multi-User SystemsHP-UX is a multi-user operating system More than one person can beusing the system at the same time. To prevent users from interferingwith each other’s work, most users cannot make changes to certain partsof the operating system. Because of this, there has to be at least oneperson who does have the ability to change the system. That person isgenerally called the “superuser”, “root user”, or system administrator.

System administrator Throughout this guide, you will see the term system administrator.The system administrator is someone who manages your system, takingcare of such tasks as adding peripheral devices, adding new users, anddoing system backups. In general, this person (who may also be calledthe system operator or the “superuser”) is the one to go to with questionsabout implementing your software. You may find it helpful to take alongcookies or other snack food when visiting your system administrator.

However, if you are the only user on a system, you will need to be yourown system administrator. In that case, whenever this guide refers youto the system administrator, you should be able to get help from thesystem administration manuals that you purchased with your system(especially Managing Systems and Workgroups) and from otherdocuments that may be installed on your system. Additionally, your HPsupport engineer can also provide installation and maintenance help, inaccordance with your support contract.

SAM Your system includes a powerful administration tool called SystemAdministration Manager (SAM) that has complete online help to guideyou through system administration tasks. Use SAM only if a systemadministrator is not available. To start SAM, log in as the superuserand type /usr/sbin/sam , then press Enter (see the next section fordetails on performing this task). For more information about SAM, seethe Managing Systems and Workgroups manual.

Page 22: Using HP-UX

22 Chapter 1

Getting StartedOverview of Your System

Trusted SystemsIn most cases the standard level of HP-UX system security is adequate tokeep your information safe and documents private. However, somecompanies or agencies may wish to use a higher level of security. If youare working in such an organization, consult you group about using thisoptional feature.

C2 security Your HP-UX system can be configured as a C2-level trusted system, asdescribed in Section 2.2 of the Department of Defense Trusted ComputerSystem Evaluation Criteria, DOD 5200.28-STD, December 1985.

When appropriately configured as a trusted system, HP-UX providesadditional security features such as discretionary access controland system auditing.

Security policy A “security policy” is a statement of the rules and practices that regulatehow an organization manages, protects, and distributes sensitiveinformation. HP-UX C2-level security expands on existing HP-UXsecurity mechanisms and provides procedures and guidelines to helpenforce your company’s security policy.

The Hewlett-Packard C2-level trusted system is made up of the HP-UXoperating system configured in trusted mode and its commands, utilities,and subsystems along with supported hardware. The system’sapplication interface must work correctly and satisfy the computingneeds of its system users. The system’s security features provide themechanisms necessary to enforce your site’s security policy and protectsystem users and their data from threats.

C2-level security features are documented as needed within this manualand additional security information is included in Chapter 7, “MakingYour System Secure.”

Page 23: Using HP-UX

Chapter 1 23

Getting StartedLogging In and Out of HP-UX

Logging In and Out of HP-UX

Login accounts This section explains how to log in, log out, and create user accounts (ifnecessary) using the command line.

Get your user name and password from the system administrator orthe support person who installed your system.

Superuser The root user, or superuser, is a special user. When logged in as thesuperuser, you have the permission required to perform all systemadministration tasks. Normally, the system administrator is the only onewho logs in as the superuser. If you are not the system administrator, youwill not log in as the superuser to perform daily tasks.

Root login However, the very first time you (or anyone else) log into your newworkstation, you must do so as root (root is the user name for thesuperuser). This is because no other user accounts have been createdyet. Once accounts have been created for other users, you should log outas superuser, then log back in as one of those users.

Logging InWhen Logging In you will see a login prompt:

Figure 1-1 Type your user name at the login prompt.

Trusted systemsrestrictions

Your system administrator may set an authorization list for a terminallimiting who can log on to specific terminals. You will only be able to logon to terminals to which you have access in this case. The systemadministrator can also set time-of-day restrictions on accounts, and youcannot log in if you try to log on at a time you are not authorized to do so.Your system administrator should inform you of any restrictions on youraccount.

Page 24: Using HP-UX

24 Chapter 1

Getting StartedLogging In and Out of HP-UX

Logging In Logging in gives you a secure way to access your system. You log in bytyping a user name and a personal password.

1. If you have a user account, type your user name after the login:prompt and press Enter .

For example:

leslie Enter

If you don't have a user account yet, ask your system administrator tocreate one, or follow the instructions in your Owner's Guide. Untilyou get a user account, you may log in as superuser.

To log in as superuser, type the following at the login: prompt:

root Enter

2. If you are logging in with your own user name, or if a password hasbeen set for root , you must enter the correct password at thePassword: prompt. Type the password and press Enter .

The password does not appear on the screen.

3. The copyright notice appears briefly, followed a message asking aboutyour console type. Type y and press Enter .

4. If you logged in with your user name, lines similar to these appear:

TERM = (hp)$

Superuser prompt If you logged in as superuser, lines similar to these appear:

Value of TERM has been set to "hp".WARNING: YOU ARE SUPERUSER !!#

Remember to get a user account for yourself (ask your systemadministrator, or see your Owner's Guide).

You are now logged in.

At this point there are literally hundreds of commands you can use toperform many types of tasks. Too bad you don’t know any yet. Keepreading and you’ll learn many of the basic commands.

Page 25: Using HP-UX

Chapter 1 25

Getting StartedLogging In and Out of HP-UX

Using HP-UX Commands

Shell Most of this guide assumes you will be using the POSIX commandinterpreter, commonly called a shell. (Other shells are available and arediscussed later in this book.) With a shell, you run a command by typingthe command's name on a command line and pressing the Enter key. Notethat Enter is the same as Return on some keyboards.

Prompt The command prompt indicates that the shell is ready for data input.Most users have a “$” as a prompt. The system administrator usually hasa “#” as a prompt.

Thus, when you see a shell and see a prompt, it looks like this:

$

For example, you can run the date command by typing:

date(1) $ date EnterThu Aug 21 15:26:23 MDT 1997$

Congratulations, you’ve entered your first command. You might enjoytrying these other “safe” commands: cal, id , who, whoami , and pwd.

NOTE What Does That “(1)” Thing Mean?

The “(1)” indicates the type of HP-UX command. Type “(1)” commandsare general commands that any user can execute. System maintenancecommand are marked as “(1M)” commands. Usually only the systemadministrator can use type “(1M)” commands. We’ll learn more aboutthis in later chapters.

The rest of this guide explains how to use HP-UX commands, andChapter 3, “Using Your Shell,” explains shells. To get visual help directlyfrom the screen while you are working with commands, see the followingsections.

Page 26: Using HP-UX

26 Chapter 1

Getting StartedLogging In and Out of HP-UX

Logging OutAfter you are done working for the day, you should log out. Logging outprevents other users from accessing your system. However, it does notprevent others from accessing your work over the network—to protectyour work, see Chapter 7, “Making Your System Secure.”

1. If you are using any applications, save your work, then exit theapplication.

2. At the shell prompt, type exit and press Enter . If you have severalwork sessions (shells) opened, you may have to type exit severaltimes before you return to the login prompt. If you are using CDE,you can press the “Exit” button to logout.

3. Once you have logged out, the system should display a “login:” promptor display a login screen.

On or off? After logging out, do not turn your computer off. Your computer is amulti-user system, and other people may be using it. If you turn it off,you will deny them access to the computer, and may cause them to losesome of their work. They may find interesting and unique ways ofexpressing their displeasure with your actions.

shutdown(1M) If you have to turn off your computer, see Managing Systems andWorkgroups for information on shutting down. Typically, the superuserwill use the shutdown(1M) command or the reboot(1M) command to shutdown a system.

Some of the newer workstations and servers will safely shut themselvesdown by simply pressing the power switch. Older systems will typically“crash” if you remove power without going through the shutdownprocedure. If a system crashes, it usually means that it will take moretime, sometimes hours, to repair the file system and return to a usablestate. If possible, ask someone if it’s safe to power-down your systembefore attempting to determine it for yourself.

Page 27: Using HP-UX

Chapter 1 27

Getting StartedModifying System Parameters

Modifying System ParametersUse this section only if you need to add or modify the system parameterinformation that was set the first time you turned on your system (seeyour Owner's Guide for details). Such modifications should be made assoon as possible after initial installation.

Log in as the superuser and type the following command:

set_parms(1M) /sbin/set_parms option Enter

Where option is one of the following:

Option… Modifies or sets…

hostname System host name

timezone Time zone

ip_address Internet Protocol address

addl_netwrk Additional network parameters

font_c-s Network font service

Any changes you make in set_parms will take effect after rebooting thesystem.

You can also use SAM to add or change most of this information.

Page 28: Using HP-UX

28 Chapter 1

Getting StartedChanging Your Password

Changing Your PasswordTypically the system administrator assigns the first password to anaccount. It is wise to change the password to one that only you know assoon as is conveniently possible. For security reasons, you shouldfrequently change your password.

A password must contain at least six characters. At least two charactersmust be alphabetic, and one of those characters must be a number or aspecial character (such as a dash (-), an underline (_), or an asterisk (*)).The password cannot contain your user name, or even a reversedversion of your user name (for example, if your user name is bif yourpassword cannot contain fib ). Also see “Choosing a Secure Password” inChapter 7, “Making Your System Secure.”

Examples of valid passwords are: wild-life , !secret , and *fuzzy* .

When you log in to the system, you may see a message informing youthat your password is about to expire. In this case, you must change yourpassword:

To change your password, from a command line shell prompt, you canuse the passwd command to set or change a password. Type:

passwd(1) $ passwd Enter

You will be prompted for your old password. Then you will be promptedto enter and re-enter your new password. The re-entered password mustmatch the first entry.

Make sure you do not forget the password you use. Writing down yourpassword on your forehead or anywhere else will defeat the purpose ofthe password. You will need to keep it secret. If you forget your password,contact your system administrator, or log in as the superuser and set anew password with the SAM utility.

Trusted systems On a trusted system, you will be required to change your passwordperiodically. This is called password aging. Also, typically you have threetries to log in successfully. If you still fail to log in, you may not be able tolog in again at that time. It is possible that your system administratormay have configured your workstation so it locks you out for some periodof time after some number of failed login attempts. For additionalinformation, see Chapter 7, “Making Your System Secure.”

Page 29: Using HP-UX

Chapter 1 29

Getting StartedFinding Information

Finding Information

ManualsThis section lists some common manuals.

System installation • If you need help with system hardware installation, see the Owner'sGuide for your system.

• If you need help with peripheral installation, see the Owner's Guidefor your system and/or the Configuring Peripherals manual.

• If you have not yet installed your HP-UX system, see the currentInstalling HP-UX manual.

HP-UX usage andadministration

• For general usage of HP-UX, continue reading this guide.

• For HP-UX system administration and troubleshooting information,see the Managing Systems and Workgroups manual.

For most system administration tasks, you can use the SAM tool.SAM contains an extensive online help system to help you performsystem administration tasks.

HP CDE usage andadministration

• For basic HP CDE information, see CDE User’s Guide.

• For advanced HP CDE configuration and system administration, seethe CDE Advanced User’s and System Administrator’s Guide.

X Window System • See Using the X Window System, HP part number B1171-90076.

manuals(1) For a complete list, see the manuals(1) manual reference page. To dothat, see the next section.

Within the United States, you can order any of the following manuals bycalling Hewlett-Packard at 1-800-227-8164. In other countries, contactyour nearest HP Sales and Support office.

CD-ROM These manuals are also available on CD-ROM, with the optional HP-UXInstant Information product. For further information on HP II, contactyour HP Sales and Support representative.

Page 30: Using HP-UX

30 Chapter 1

Getting StartedFinding Information

Online DocumentsThere are also online documents to be found on your system. Many ofthese documents are in the /usr/share/doc directory.

Manual Reference Pages

Man pages The HP-UX Reference contains reference entries (also called manualpages or “man pages”) for nearly every HP-UX command.

These manual reference pages provide command syntax and a detaileddescription of the command and its options and arguments. Thedescription may include examples of command usage and provide otherinformation such as system files used and related commands.

To display the man pages from the command line, type mancommand_name at the command prompt. For example, to learn moreabout the cp command type:

man(1) man cp

After a few seconds, an information display appears. For commandsyntax, refer to the “SYNOPSIS” section of the man page. Brackets, [ ], ina syntax statement indicate that the enclosed parameter is optional.

Printing man pages To print a man page, type the following:

man command_name | col -b | lp

The col -b filters and formats the man page, and the lp commandsends it to the default printer.

NOTE What does that vertical-bar character “|” mean?

The “|” character represents a pipe command. A pipe is used to connectthe output of one command as the input of another command.

Page 31: Using HP-UX

Chapter 1 31

Getting StartedFinding Information

You can even look at the man man-page to learn more about the mancommand itself:

man(1) man man

man(1) man(1)

NAMEman - find manual information by keywords;

print out a manual entry

SYNOPSISman -k keyword...man -f file...man [-] [section[subsection]] entry_name...

DESCRIPTIONman accesses information from the onlineversion of the HP-UX Reference. It can beused to:

- More -(11%)

more(1) The message - More -(11%) means you have viewed 11% of the file,and 89% remains. (Some systems will just display - More - ). At thispoint, you can do any of the following:

• Scroll through the file a page at a time by pressing the space bar.

• Scroll through the file a line at a time by pressing Enter .

• Quit viewing the man page by pressing Q.

Page 32: Using HP-UX

32 Chapter 1

Getting StartedFinding Information

Page 33: Using HP-UX

33

2 Working with Files andDirectories

Many tools HP-UX provides numerous tools to work with files and directories. Thereare commands to create, remove, group, move, and maintain both filesand directories.

A file is a named area on your system containing stored information.

A directory is a kind of file that can contain other files and directories.

To do this ... See ...

Creating files page 34

Listing files page 35

Naming files page 36

Viewing or printing files page 38

Renaming, copying, removing files page 41

Comparing, joining files page 43

Understanding hierarchies page 45

Understanding pathnames page 50

Creating directories page 54

Changing directories page 56

Moving files between directories page 58

Copying directories page 60

Removing directories page 61

Using filename wildcards page 63

Searching inside of files page 65

Finding files page 67

Page 34: Using HP-UX

34 Chapter 2

Working with Files and DirectoriesCreating a File

Creating a FileYou can use the cat command to create a file containing text. Forexample, to create the file “myfile”, use the cat command as follows:

cat(1) $ cat > myfile

After you type this command, the cursor sits on the first line of the emptyfile. Type your text and press Enter at the end of each line. To exit the file,hold down CTRL and press D. The cat command returns you to thecommand line prompt.

You can use the cat command to create your own version of myfile . Forexample, you might create the file as follows:

$ cat > myfileThe text I am typing will be stored in "myfile". EnterI press RETURN at the end of each line. EnterWhen I'm finished, I hold down the CTRL key and press D. EnterCTRL- D

NOTE It’s easier to use an editing program.

You can also create and edit files using a text editor such as vi . To learnhow to use this editor, see Chapter 4, “Using the vi Editor.”

NOTE What Does That “(1)” Thing Mean?

As we mentioned in the last chapter, the “(1)” indicates the type ofHP-UX command. If it is confusing, you may wish to read about manualpages at the end of the previous chapter.

Page 35: Using HP-UX

Chapter 2 35

Working with Files and DirectoriesListing Files

Listing FilesTo verify that cat created myfile , run the ls command, which lists thenames of your files. Running the ls command with the file name willconfirm that the file exists, but won't list other files.

ls(1) $ ls myfilemyfile The ls command lists myfile.

To see additional information about a file, use the ll (long listing)command.

ll(1) $ ll myfile-rw-r--r-- 1 myname mygroup 146 Aug 4 14:13 myfile

The mysterious characters at the beginning of the line (-rw-r--r--)indicate the owner’s, the group’s and other people’s permissions to readand/or write the file. The “1” indicates how many links (or names) areassociated with this file, the “myname” is typically your login name, the“mygroup” is the name assigned by the administrator to the group ofusers who work with you, the “146” is the number of bytes (characters) inthe file, followed by the date the file as last modified, followed by the file’sname.

For more information about the ll command and access permissions, seeChapter 7, “Making Your System Secure.”

Viewing files Viewing the file's contents is discussed in “Viewing and Printing Files” inthis chapter.

Page 36: Using HP-UX

36 Chapter 2

Working with Files and DirectoriesNaming Files

Naming FilesWhen you choose a file name, you need to follow certain rules regardingthe length of the name and the types of characters you include.

Guidelines for File NamesWhen you choose a file name, remember these rules:

• Generally, file names can contain up to 256 characters (or bytes, innon-ASCII character sets). These characters can be any combinationof the following:

• Uppercase or lowercase letters (A through Z; a through z )

• Digits (0 through 9)

• Special characters, such as: +, - , _, .

Based on these rules, the following are valid file names:

Valid names money Acct.01.87 CODE.clost+found 112.3-data foo_bar

• HP-UX interprets uppercase and lowercase letters differently in filenames. Thus, the following file names all are different:

money Money MoneY MONEY

NOTE Short File-Name Systems

On some computers, file names cannot be longer than 14 characters. Ifyou are not sure if your computer can support longer file names, checkwith your system administrator. You could also create a file with a verylong name and see if its name becomes truncated.

Page 37: Using HP-UX

Chapter 2 37

Working with Files and DirectoriesNaming Files

Invisible File NamesA file name in which the first character is a dot (.) is an invisible filename, since the ls command does not normally display it. Use invisiblefile names if you don't want or need certain files displayed when you runls .

To illustrate, you have an invisible startup file that the system runswhen you log in, a login script. It is used to customize your workingenvironment. To learn more about login scripts, see “Using Login Scriptsto Set the System Environment” in Chapter 3, “Using Your Shell.”

To cause ls to list invisible file names, including the name of your loginscript, run it with the -a option:

$ ls -a Use -a to see invisible file names..profile myfile This is the POSIX Shell, so .profile is shown.

Invisible files, or “dot files” are often used to store configurationinformation. Be careful not to remove these files without understandingwhat they doing for you.

Page 38: Using HP-UX

38 Chapter 2

Working with Files and DirectoriesViewing and Printing Files

Viewing and Printing FilesUsing the more command, you can view a text file one screenful at atime. If your system is appropriately configured, you can print a text fileusing the lp command.

Viewing a File with moreThe more command displays a text file's contents on the screen. Forexample, the following more command displays the contents of myfile(which you created in “Creating a File”):

more(1) $ more myfileThe text I am typing will be stored in "myfile".I press RETURN at the end of each line.When I'm finished, I hold down the CTRL key and press D.

If the file contains more lines than are on your screen, more pauses whenthe screen is full. With a longer file, press space to continue looking atadditional screens, and press Q when you are finished. Then morereturns you to the system prompt.

Try running more on the system file /etc/passwd :

$ more /etc/passwdroot:XOSDMfBA.hqs6:0:3::/:/usr/bin/shdaemon:*:1:5::/:/usr/bin/shbin:*:2:2::/bin:/usr/bin/shadm:*:4:4::/var/adm:/usr/bin/sh

More(4%)

The “More(4%) ” message at the bottom of the screen means you haveviewed 4% of the file thus far, and 96% of the file remains to be viewed.At this point, you can do any of the following:

• Scroll through the file a page at a time by pressing the space bar.

• Scroll backwards a page at a time by pressing B.

• Scroll through the file a line at a time by pressing Enter .

• Quit viewing the file and leave more by pressing Q.

Page 39: Using HP-UX

Chapter 2 39

Working with Files and DirectoriesViewing and Printing Files

Displaying the First and Last Lines of a FileWe often want to see just the beginning (head) of a file or just the end(tail) of a file.

• To see the first line of a file without using a text editor, use the headcommand:

head(1) $ head filename

This will display, by default, the first ten lines of filename, includingblanks. For example:

CONFERENCE NOTES

Attendees:

MarySamNinaGeorgeRaphaelSergei

• To see the last ten lines (default value) of your file, use the tailcommand:

tail(1) $ tail filename

You will see the last ten lines (including blanks) of filename.

Both head and tail take numeric arguments. For example, use thiscommand to display the first 25 lines of file1 : head -25 file1

Page 40: Using HP-UX

40 Chapter 2

Working with Files and DirectoriesViewing and Printing Files

Printing a File with lpYou can print a text file using the lp (line printer) command. Forexample:

lp(1) $ lp myfile

The lp command displays a message indicating that it sent your file tothe printer. For example:

request id is lp- number (1 file)

The number is an ID number assigned to the print job by the lpcommand. If you don't see this message, or if you get an error message,consult your system administrator. You should get a printout with yourusername displayed on the first page. The time required for a printoutdepends on the number of tasks being run by the system and the speed ofthe printer itself.

To configure printers and set up the lp spooler, use the SystemAdministration Manager (SAM). For command-line printerconfiguration, see the Configuring HP-UX for Peripherals manual. Forcommand-line spooler configuration, see the System AdministrationTasks manual.

Getting Printer Information with lpstat

To display a report on the printer status, including the order of yourprint job in the printer queue, type:

lpstat(1) $ lpstat -t

Canceling a Print Request with cancel

To cancel a print request, enter the cancel command with the IDnumber of your request:

cancel(1) $ cancel request_id

Page 41: Using HP-UX

Chapter 2 41

Working with Files and DirectoriesRenaming, Copying, and Removing Files

Renaming, Copying, and Removing FilesTo change a file's name, use the mv (“move”) command; to make a copy ofa file, use the cp (“copy”) command; to remove a file, use the rm(“remove”) command.

Renaming Files with mvUsing the mv command, you can rename the file myfile to foofile asfollows:

mv(1) $ mv myfile foofile

To verify that mv renamed the file, use the ls command:

$ lsfoofile

To rename foofile back to myfile , type:

$ mv foofile myfile$ ls Using ls, verify that the action was successful.myfile

CAUTION If you move a file to an existing file, the existing file will be lost.

When renaming files, take care not to rename a file to the name of a filethat already exists in that directory. If you do this, the file that alreadyhas the name will be lost. To ensure that you do not accidentally removean existing file, use the -i option. For example:

$ mv -i myfile foofile

In this case, if foofile exists, the above command asks for confirmationbefore removing it.

The mv command can also be used to move files to different locations onthe system. See “Moving and Copying Files between Directories”.

Page 42: Using HP-UX

42 Chapter 2

Working with Files and DirectoriesRenaming, Copying, and Removing Files

Copying Files with cpCopy a file when you want to make a new version of it while still keepingthe old version around. For example, to make a new copy of myfilenamed myfile2 , type:

cp(1) $ cp myfile myfile2

Now when you use the ls command, you will see the following:

$ lsmyfile myfile2

Use more to view myfile2 . You will find that it is the same as myfile .

CAUTION If you copy a file to an existing file, the existing file will be lost.

To ensure that you never accidentally overwrite an existing file, use the-i option. For example, if you attempt to copy myfile to myfile2 in thecurrent directory and myfile2 already exists, cp asks for permission tooverwrite myfile2 :

$ cp -i myfile myfile2overwrite myfile2? (y/n)

Removing Files with rmIf you have files that are no longer needed, you should remove (delete)them. Deleting unnecessary files leaves more room for other files on yoursystem. For example, suppose you have finished using myfile2 , and it isno longer needed. To remove myfile2 , type:

rm(1) $ rm myfile2

To see that myfile2 was removed, use ls :

$ ls The directory listing shows the remaining file.myfile

NOTE To cause the rm command to prompt you for permission before deletingany file, use the -i option:

$ rm -i myfilemyfile: ? (y/n)

See “Removing Directories” for information on how to remove directoriesand contents.

Page 43: Using HP-UX

Chapter 2 43

Working with Files and DirectoriesComparing the Contents of Two Files

Comparing the Contents of Two FilesIf two text files are known to be similar, and you want to determine whatthe differences are or which one has been changed:

1. First run ll and look at the date and time fields showing when eachfile was last saved. For example:

-rw-r--r-- 1 jim users 1759 Mar 17 15:53 test1-rw-r--r-- 1 jim users 2130 Mar 17 15:47 test2

test1 was saved more recently than test2 , because it has the morerecent time (and its size was also changed).

2. You can determine the differences between test1 and test2 byrunning the diff command:

diff(1) $ diff test1 test2

For example, if test1 contains:

You are in a maze oftwisty little passageswhich are all alike.

And test2 contains:

You are in a maze oftwisty little passageswhich are all different.

The command will indicate the differences it found, by line number, andpoint (with < and >) to which file the difference occurred in:

3c3 The relevant line numbers< which are all alike. The version in test1---> which are all different. The version in test2

Note how the diff command is telling you that if you were to remove “<”the one line, and add “>” the other line, the two files would be the same.

Page 44: Using HP-UX

44 Chapter 2

Working with Files and DirectoriesJoining Two Files

Joining Two FilesTo append to an existing file, you use the cat command with twogreater-than signs (>>). The file name following the >> identifies the fileto which the contents of the first file is appended. If that file exists, thenew data is appended to the end of the file. If the file does not exist, it iscreated. The command format is:

cat(1) $ cat filename2 >> filename1

where filename2 is the file whose output is redirected, and filename1 isthe name of the file that is appended to.

This also works with the output of commands. The following exampleexecutes the date command with the output redirected to append to thewhoison file:

$ date >> whoison Append output to whoison.$ more whoison Display contents of whoison.pat console Oct 4 08:50 Output from previous example.terry tty01 Oct 4 11:57kim tty02 Oct 4 08:13Tue Oct 4 13:20:16 MDT 1994 Newly appended output from date.

Page 45: Using HP-UX

Chapter 2 45

Working with Files and DirectoriesUnderstanding a Directory Hierarchy

Understanding a Directory Hierarchy

Directory tree HP-UX directories can contain files and other directories. Therefore, adirectory usually has a parent directory “above” and may also havesubdirectories, or child directories “below” within it. Similarly, eachsubdirectory can contain other files and also can have moresubdirectories. Because they are hierarchically organized, directoriesprovide a logical way to organize files.

With the help of directories, you can organize your files into manageable,logically related groups. For example, if you have several files for each ofseveral different projects, you can create a directory for each project andstore all the files for each project in the appropriate directory.

The structure of an HP-UX directory resembles an inverted tree. Thesedirectories (shown in the figure below as ovals) usually contain moredirectories; thus, the typical home directory develops a branching treestructure.

Page 46: Using HP-UX

46 Chapter 2

Working with Files and DirectoriesUnderstanding a Directory Hierarchy

Figure 2-1 A Typical HP-UX Directory Structure

Page 47: Using HP-UX

Chapter 2 47

Working with Files and DirectoriesUnderstanding a Directory Hierarchy

Each directory also contains files (represented below as boxes), whichhold actual text, data, or code. At the top of the inverted tree structure isthe root directory, represented in path names as / . This figure shows abroader part of a system's directory structure.

Figure 2-2 A System Directory Structure

Page 48: Using HP-UX

48 Chapter 2

Working with Files and DirectoriesDetermining Your Location in an HP-UX Directory Hierarchy

Determining Your Location in an HP-UXDirectory HierarchyThis section discusses the HP-UX directory structure and how youspecify the location of a file in the structure. All directories fall under thetopmost root directory, which is denoted by a slash (/ ). When you useHP-UX, you are working in a directory called the current workingdirectory. And when you log in, HP-UX places you in your homedirectory.

The figure below shows the two highest levels of a typical HP-UXdirectory structure. Each directory, including the root, may containlogically organized files, as well as more directories.

Figure 2-3 The HP-UX Directory Structure

Page 49: Using HP-UX

Chapter 2 49

Working with Files and DirectoriesDetermining Your Location in an HP-UX Directory Hierarchy

Here is a sample directory hierarchy for a user named Leslie. WhenLeslie logs in, she is in her home directory, leslie .

Figure 2-4 Leslie's Home Directory

pwd(1) To determine your location in the directory hierarchy, use the pwd (printworking directory) command. The pwd command displays the “path”from the root directory to your current working directory.

For example:

$ pwd/home/engineers/leslie

Page 50: Using HP-UX

50 Chapter 2

Working with Files and DirectoriesSpecifying Files and Directories

Specifying Files and DirectoriesWhen specifying files in your current working directory, you can refer tothem just by their file names. But when referring to directories and filesoutside your current working directory, you must use path names,which tell HP-UX how to get to the appropriate directory.

Absolute Path NamesAbsolute path names specify the path to a directory or file, starting fromthe root directory at the top of the inverted tree structure. The rootdirectory is represented by a slash (/). The path consists of a sequentiallist of directories, separated by slashes, leading to the directory or fileyou want to specify. The last name in the path is the directory or file youare pointing to.

Here is an example of an absolute path, displayed with the pwdcommand:

$ pwd/home/engineers/leslie

This specifies the location of the current directory, leslie , by startingfrom the root and working down.

Page 51: Using HP-UX

Chapter 2 51

Working with Files and DirectoriesSpecifying Files and Directories

The figure below shows the absolute path names for various directoriesand files in a typical directory structure:

Figure 2-5 Absolute Path Names

Page 52: Using HP-UX

52 Chapter 2

Working with Files and DirectoriesSpecifying Files and Directories

Relative Path NamesYou can use a relative path name as a shortcut to the location of files anddirectories. Relative path names specify directories and files startingfrom your current working directory (instead of the root directory).

This relativepath name… Means…

. The current directory.

.. The parent directory (the directory above the currentdirectory).

../.. Two directories above the current directory.

directory_name The directory below the current directory.

For example, suppose the current directory is/home/engineers/leslie . To list the files in the directory above(which is /home/engineers ), enter:

$ ls ..arnie leslie sally

To list the files in a directory immediately below your current directory,simply enter the directory name. For example, to list the files in theprojects directory, below the current directory/home/engineers/leslie , enter:

$ ls projects$ The projects directory is empty.

Page 53: Using HP-UX

Chapter 2 53

Working with Files and DirectoriesSpecifying Files and Directories

The following figure shows relative path names for various directoriesand files starting from the current directory,/home/engineers/leslie .

Figure 2-6 Relative Path Names from /home/engineers/leslie

Page 54: Using HP-UX

54 Chapter 2

Working with Files and DirectoriesCreating Directories

Creating DirectoriesTo create a directory, use the mkdir (make directory) command. Afteryou create a directory, you can move files into it, and you can even createmore directories underneath it. For example, to create a subdirectory inyour current working directory named projects , type:

mkdir(1) $ mkdir projects

To verify its creation, you can use either the ls or lsf command to listthe contents of the directory. Both commands display the new directory,but lsf appends a slash (/ ) to the end of directory names to differentiatethem from file names. For example:

$ lsmyfile projects It did what you expected.

lsf(1) $ lsfmyfile projects/ The lsf command appends a slash to directory names.

This figure shows the resulting directory structure under/home/engineers :

Figure 2-7 Creating the “projects” Directory

Page 55: Using HP-UX

Chapter 2 55

Working with Files and DirectoriesCreating Directories

Use mkdir as follows:

$ mkdir new_dir_path

where new_dir_path is the path name of the directory you want to create.For example, to create two directories named old and new under theprojects directory, type:

$ mkdir projects/old$ mkdir projects/new$ lsf projectsnew/ old/

Figure 2-8 Structure after Creating New Directories

Page 56: Using HP-UX

56 Chapter 2

Working with Files and DirectoriesChanging Your Current Directory

Changing Your Current DirectoryTo change your current working directory, use the cd command. Forexample, cd projects moves you into the directory projects (whichyou created in “Creating Directories”).

To verify your location, use the pwd command, which displays yourcurrent directory. For example, if your home directory was/home/leslie and you ran the “cd projects ” command, pwd woulddisplay the following:

$ pwd/home/leslie/projects

To move into the directory new under projects , type:

cd(1) $ cd new$ pwd Verify where you are./home/leslie/projects/new

Remember that .. is the relative path name for the parent directory ofyour current working directory. So to move up one level, back toprojects , type:

$ cd ..$ pwd Show your current working directory./home/leslie/projects It was successful.

NOTE Finding your way home:

Experiment with the cd and pwd commands to move around yourdirectory structure. If you become lost, don't panic; just remember thatyou can type cd to return to your home directory. For example:

$ cd$ pwd Are you back home?/home/leslie Yes!

Page 57: Using HP-UX

Chapter 2 57

Working with Files and DirectoriesChanging Your Current Directory

The following figure illustrates how various cd commands change yourcurrent working directory. The example assumes you're starting at thedirectory /home/leslie/projects , and that your home directory is/home/leslie .

Figure 2-9 Effect of Various “cd” Commands

Absolute path You can also get to any directory using its absolute path name. Forexample, to change to the projects directory in the example hierarchy,enter:

$ cd /home/leslie/projects

Page 58: Using HP-UX

58 Chapter 2

Working with Files and DirectoriesMoving and Copying Files between Directories

Moving and Copying Files betweenDirectoriesThe mv command lets you move a file from one directory to another. Withthe cp command, you can copy a file into a different directory.

Moving FilesTo move files from one directory to another, use the mv command.

$ mv from_path to_path

where from_path is the file name or path name of the file you want tomove, and to_path is the name of the path where you are moving the file.For example, to move myfile into the projects directory, type:

$ cd Move to home directory first.$ mv myfile projects

A single dot (. ) for a path name represents your current workingdirectory. So, to move myfile from the projects directory back to yourcurrent working directory, type:

$ mv projects/myfile . Don't forget the dot.

CAUTION If you rename a file to an existing file, the existing file will be lost.

When renaming files, take care not to rename a file to the name of a filethat already exists in that directory. If you do this, the file that alreadyhas the name will be lost. To ensure that you do not accidentally removean existing file, use the -i option. For example:

$ mv -i myfile /home/leslie/foofile

If /home/leslie/foofile exists, the above command asks forconfirmation before removing it.

Page 59: Using HP-UX

Chapter 2 59

Working with Files and DirectoriesMoving and Copying Files between Directories

Copying FilesTo copy a file into a different directory, use the cp command.

$ cp from_path to_path

where from_path is the file name or path name of the file you want tocopy, and to_path is the path name of the directory or file to which youare copying.

For example, to make a copy of myfile named myfile2 in theprojects directory, type:

$ cp myfile projects/myfile2$ lsfmyfile projects/ The file myfile still exists.

$ lsf projectsmyfile2 new/ old/ The copy (myfile2) is in projects.

To make a new version of myfile2 named myfile3 in your currentdirectory, type:

$ cp projects/myfile2 myfile3$ lsfmyfile myfile3 projects/

CAUTION If you copy a file to an existing file, the existing file will be lost.

To ensure that you never accidentally overwrite an existing file, use the-i option. For example, if you attempt to copy /home/leslie/myfileto myfile2 in the current directory and myfile2 already exists, cp asksfor permission to overwrite myfile2 :

$ cp -i /home/leslie/myfile myfile2overwrite myfile2? (y/n)

Page 60: Using HP-UX

60 Chapter 2

Working with Files and DirectoriesCopying Directories

Copying DirectoriesTo copy entire directories, use the -r option of the cp command.

For example, if you have a directory called mydir that contains myfileand newfile , you can copy the directory to a new directory calledmydir2 . mydir2 will also contain a copy of myfile and newfile . Usethe following command:

$ cp -r mydir mydir2

The -r option copies any files and subdirectories below the specifieddirectory.

NOTE Where did the directory go?

If the destination directory already exists, the directory you are copyingwill become a subdirectory under the existing destination directory. Ifthe destination directory does not exist, it will be created.

Page 61: Using HP-UX

Chapter 2 61

Working with Files and DirectoriesRemoving Directories

Removing DirectoriesYou can remove an empty directory with the rmdir command. To removea directory and all of its contents in one step, use the rm command withthe -rf option.

After you have removed a directory, you can no longer use it, and it willno longer appear in an ll or other listing of the directory above it.

Removing a Directory with rmdirBefore removing a directory with rmdir , you must remove any visible orinvisible files and any directories under it. For example, suppose youwant to remove the projects directory and its files:

Figure 2-10 The “projects” Directory Structure

Page 62: Using HP-UX

62 Chapter 2

Working with Files and DirectoriesRemoving Directories

To remove this structure, run the following sequence of commands:

$ cd Move back to your home directory$ lsf List the files and directories.myfile myfile3 projects/$ rmdir projects Try to remove projects.rmdir: projects not empty It won't let you.$ cd projects Change directory to projects.$ lsf List its contents.myfile2 new/ old/$ rm myfile2 Remove file myfile2.$ lsf Check if it is gone.new/ old/$ rmdir new Remove directory new. If it's empty, rmdir removes it.$ lsf Check if it is gone.old/$ rmdir old Now remove the old directory. If empty, rmdir removes it.$ lsf There is no message; the action was successful.$ cd Now move back to your home directory.$ rmdir projects$ lsf Verify that it worked.myfile myfile3$

Removing Everything with rm -rfTo avoid having to empty a directory before removing it, you can removea directory and all its files and directories in one action by typing thefollowing:

$ rm -rf dirname

CAUTION Use rm -rf with great caution, since it does remove a directory and all itscontents, irretrievably, in one action.

Page 63: Using HP-UX

Chapter 2 63

Working with Files and DirectoriesFile Name Shorthand: Wildcard Characters

File Name Shorthand: WildcardCharactersWildcard characters provide a convenient shorthand for specifyingmultiple file or directory names with one name. Two of the most usefulwildcard characters are * and ?. The * matches any sequence (string) ofcharacters (including no characters), and the ? matches any onecharacter.

The * WildcardThe * wildcard means “any characters, including no characters.” Supposeyou have created the following files in your current working directory:

$ lsfmyfile myfile2 myfile3 xenic yourfile

To list only the file names beginning with “myfile ”, type:

$ lsf myfile*myfile myfile2 myfile3

To list file names containing “file ”, type:

$ lsf *file*myfile myfile2 myfile3 yourfile

The ? WildcardThe ? wildcard means “any single character.” Although you probablywon't use the ? wildcard as much as * , it is still useful. For instance, ifyou want to list only the files that start with myfile and end with asingle additional character, type:

$ lsf myfile?myfile2 myfile3

The ? wildcard character matches exactly one character. Thus, myfiledidn't show up in this listing because it didn't have another character atthe end.

Page 64: Using HP-UX

64 Chapter 2

Working with Files and DirectoriesFile Name Shorthand: Wildcard Characters

Using the * Wildcard Character with mv, cp,and rmWildcard characters are often useful when you want to move or copymultiple files from one directory to another. For example, suppose youhave two directories immediately below your current directory, namednew and old , and these directories contain the following files:

$ lsf newmyfile myfile2lsf oldmyfile3 myfile4

To move all the files from the directory new into the directory old , type:

$ mv new/* old$ lsf new The files are no longer in new.lsf oldmyfile myfile2 myfile3 myfile4 They are in the directory old.

You can do a similar operation with the cp command. For example, tocopy all the files from old into new, type:

$ cp old/* new

Similarly, you can use wildcard characters with the rm command. Forexample, to remove all the files in the directory new, type:

$ rm new/*

CAUTION It’s easy to remove too much.

When using wildcards, be careful not to accidentally remove files youneed. Sometimes it’s helpful to substitute the ls command for the rmcommand if you want to see which filenames match a pattern.

For More Information…See the regexp(5) man page for general features of * and ?. Foradditional features relating to individual shells: if you use the POSIXShell, see sh-posix(1) man page; if you use the C shell, see the csh(1) manpage.

Page 65: Using HP-UX

Chapter 2 65

Working with Files and DirectoriesSearching for Text Patterns using grep

Searching for Text Patterns using grepYou can use the grep (“global r egular expression print”) command tosearch for a text pattern within a file or to display the names of files thatcontain a specified text pattern. This command is useful when you wantto search for information in files or directories.

The grep command looks at each line of one or more files for a text stringthat matches a specified pattern. When it finds a matching text string, itdisplays the line in which the matching string is found.

Searching a File for a Text StringSuppose you have a mailing list called mailist with the contents shownbelow:

Smith, Joe 2345 Pine St. Santa Clara, CAWalsen, Stacey 493 Winkle Ave. San Jose, CADiaz, Robert 6789 Pine St. Santa Clara, CAWang, Michael 1832 Jackson St. Santa Clara, CA

If you want to extract the addresses of all the people on Pine Street,enter:

grep(1) $ grep Pine mailist

The grep command lists all lines in mailist that contain the stringPine . The output is:

Smith, Joe 2345 Pine St. Santa Clara, CADiaz, Robert 6789 Pine St. Santa Clara, CA

To make the search case-insensitive, use the -i option. For example:

$ grep -i pine mailist

Page 66: Using HP-UX

66 Chapter 2

Working with Files and DirectoriesSearching for Text Patterns using grep

Searching Multiple FilesThe grep command can be useful in other ways. Sometimes, you want tofind information, but are not sure in which file it is located.

Suppose you have three mailing lists, and cannot remember whichcontains Stacey Walsen's address. Enter:

$ grep 'Walsen, Stacey' mailist mailist2 mailist3mailist: Walsen, Stacey 493 Winkle Ave. San Jose, CA

The grep command displays the line containing Stacey's address and thefile in which it was found. Note that because it contains a space, thestring must be surrounded by single quotes ('Walsen, Stacey ').

To search the entire current directory for this information, enter:

$ grep 'Walsen, Stacey' *

See the grep(1) man page in the HP-UX Reference for more informationon using the grep command.

Page 67: Using HP-UX

Chapter 2 67

Working with Files and DirectoriesSearching for Files using find

Searching for Files using findYou can use the find command to search through a directory and itssubdirectories for files meeting certain criteria. You can then execute acommand on the files you've found.

Finding Files that Match a PatternAlthough the syntax of find can be complex, it may help you use HP-UXmore productively. It is a powerful and flexible command. However, itmay run slowly, especially if it is searching many directories.

Suppose you want to display all files in the current directory and itssubdirectories that begin with d. Enter:

find(1) $ find . -name 'd*'

The dot (.) causes find to search the current directory and itssubdirectories. The -name option followed by a file name or a file namepattern (in this case d* ) tells find to search for all file names that matchthat pattern. In this example, find will look for all file names beginningwith d.

Note that d* is enclosed by single quotes 'd* '. If you use a file namepattern in the find command, you must quote it so that the shell willinterpret it correctly.

Finding Files that are Newer than a CertainFileSuppose you want to display all files modified after a certain file. Todisplay all files newer than myfile in the /home/leslie directory andits subdirectories, enter:

$ find /home/leslie -newer myfile

This example can be read as follows: in directory /home/leslie and itssubdirectories, find all files modified after myfile . (To determine when afile was last modified, use the ll command.)

Page 68: Using HP-UX

68 Chapter 2

Working with Files and DirectoriesSearching for Files using find

Running Commands on FilesYou can execute commands on files located with the find command.Let's say you want to remove all files with a .tmp extension in thecurrent directory and its subdirectories. Enter:

$ find . -name '*.tmp' -exec rm {} \;

This example finds and displays on the screen all files in the currentdirectory and its subdirectories that end in .tmp , then deletes these files.The -exec option causes the following command (rm) to be executed. Thebrackets { } represent the files found with the find command. Thesemi-colon that ends the exec string is escaped with a backslash (\;).

Using Logical OperatorsThe syntax of find includes the logical Boolean operators NOT, AND,and OR.

To find files that do not match a specific pattern, use the logical NOToperator, the exclamation mark (! ). After using this operator, you mustuse options to define file attributes such as file name. Then, files arefound that do not have the attributes you specify.

For example, to find all files in /tmp that are not owned by leslie , usethis command:

$ find /tmp \( ! -user leslie \)

The \ escapes the parentheses so that they are not interpreted as specialcharacters by the shell.

To find files that have two distinct attributes, use the logical ANDoperator, expression -a expression. For example, to find all directories in /that are owned by leslie , use this command:

$ find / \( -type d -a -user leslie \)

To find files that have either or both of two attributes, use the logical ORoperator, expression -o expression. For example, to remove all files endingwith .o or named a.out that have not been accessed for a week, use thiscommand:

$find / \( -name a.out -o -name '*.o' \) -atime +7 -exec rm {} \;

For More Information…See the find(1) man page for more information on using the findcommand.

Page 69: Using HP-UX

Chapter 2 69

Working with Files and DirectoriesChapter Command Summary

Chapter Command SummaryTo Do This… Type This…

Create a file cat > filename

Terminate keyboard input for cat CTRL-D

List visible files in currentdirectory ls

List all files in current directory ls -a

List files; show directories with "/ "lsf

View a file more filename

Print a file lp myfile

Get information on a print job lpstat

Cancel a print job lpno cancel lpno

Rename (move) a file mv fromfile tofile

Copy a file cp fromfile tofile

Delete (remove) a file rm filename

Change directory cd directory_path

Change to home directory cd

Display working directory pwd

Remove an (empty) directory rmdir directory_name

Remove a directory and contents rm -rf directory_name

Search a file for a text pattern grep ' text' filename

Search for a file and display outputon screen find dir_path -name filename

Page 70: Using HP-UX

70 Chapter 2

Working with Files and DirectoriesChapter Command Summary

Page 71: Using HP-UX

71

3 Using Your Shell

Command Interpreter HP-UX provides several command interpretation programs called shells.A shell is the interface between HP-UX and you. The shell interprets thetext you type and the keys you press, then directs the HP-UX operatingsystem to take an appropriate action.

To do this ... See ...

Understand command syntax page 72

Understand processes page 74

Understand input, output, and error page 76

Understand pipes page 83

Changing your shell page 86

Editing in a shell page 90

Recalling previous commands page 92

Setting the login environment page 94

Using login scripts page 97

Setting variables page 99

Setting the search path page 101

Setting terminal characteristics page 104

Page 72: Using HP-UX

72 Chapter 3

Using Your ShellUnderstanding Command Syntax

Understanding Command SyntaxHP-UX has many useful commands that will help you handle data andtext, do system administration tasks, and find information. Most of thesecommands are easy to enter, that is, they are either a command withoutany arguments (whoami ), or a command whose only argument is a filename (mkdir projects ). HP-UX commands can also be more complex,having additional options, arguments, or both.

Options change a command's behavior. For example, in Chapter 2,“Working with Files and Directories,”, you used the -a option to changethe behavior of the ls command so you could list invisible file names. Ingeneral, command options are preceded by a dash (- ). Argumentsprovide additional information needed by the command, such as thename of the file on which to run the command.

Examples Using OptionsWhen used without options, the rm command removes a file withoutverifying whether you really want to remove it. Suppose, for example,your current working directory contains these files: myfile , myfile1 ,myfile2 , myfile3 , and myfile4 . You could remove all these files bytyping this command:

$ rm my*$ All the files are removed, no questions asked.

To cause rm to prompt you for verification before removing each file, usethe -i (interactive) option:

$ rm -i my*myfile1: ? (y/n) y Type y to remove the file.myfile2: ? (y/n) ymyfile3: ? (y/n) ymyfile4: ? (y/n) n Or, type n to leave it alone.$ lsmyfile4 myfile4 was not removed.

If you are using rm non-interactively and the file does not have writepermission (for example, with -r--r--r-- permission, as displayed in along listing), then a message something like this will be displayed:

filename: 444 mode ? (yes/no)

Respond with y if you want to remove the file.

Page 73: Using HP-UX

Chapter 3 73

Using Your ShellUnderstanding Command Syntax

Examples Using ArgumentsThe cal command displays an English calendar for the current month.With multiple command arguments, you can specify which calendarmonth and year to display. For example, to display a calendar forFebruary 1998, type the cal command as follows:

cal(1) $ cal 2 1998February 1998

S M Tu W Th F S1 2 3 4 5 6 78 9 10 11 12 13 14

15 16 17 18 19 20 2122 23 24 25 26 27 28

Be sure to include the century, 19 . If you use 98 as the argument, youwill get a calendar for the year 98 A.D.

Enclosing Arguments in QuotesWhen a single command argument contains embedded blanks, you mustenclose it between quotes ('word1 word2'). For example, the followinggrep command displays all lines in myfile containing “I am ”:

grep(1) $ grep 'I am' myfileThe text I am typing will be stored in "myfile".

Running Multiple Commands on the SameCommand LineOccasionally, you may find it useful to run two or more commands on thesame command line. To do so, separate the commands with a semicolon,as illustrated below:

Using ; $ whoami ; dateleslie Output from whoamiTue Sep 16 12:01:55 MDT 1997 Output from date

You can also connect commands, using the output of one as input toanother. See “Piping Command Output and Input”.

Page 74: Using HP-UX

74 Chapter 3

Using Your ShellUnderstanding Processes

Understanding ProcessesThe shell interprets your keyboard commands for the HP-UX operatingsystem to act on. When you log in, you are said to be “in” a shell. Afterthe shell interprets a command line, HP-UX loads into memory thecorresponding program. When a program is running, it is called aprocess. HP-UX assigns every process a unique number, known as aprocess identifier (PID).

How Processes are Created

ps(1) When you log in, HP-UX starts your shell. During login, HP-UX copiesthe shell program from system disk into memory. When it is in memory,the shell begins executing, and it becomes a process that lasts until youlog out. Process, then, refers to the copied program that is activelyexecuting in memory, while program is the file stored on the disk.

Similarly, the commands you type create processes. After you type acommand line, the following events take place:

1. The shell interprets the command line and searches the disk until itfinds the requested program.

2. The shell asks HP-UX to run the program; then control transfersfrom the shell to HP-UX.

3. HP-UX copies the specified program from a disk file into memory.When the program resides in memory, it begins executing — and aprocess is created.

4. Each process is assigned a Process Identifier or PID. You can findout what processes are currently running on your system by typingps -ef .

5. When a program finishes executing, control transfers back to theshell, and the process disappears.

Page 75: Using HP-UX

Chapter 3 75

Using Your ShellUnderstanding Processes

Stopping a Process with killNormally, processes can be terminated by entering the following, wherePID is the identification number for the process you want to get rid of.

kill(1) $ kill PID

The PID for the process is determined by running ps -ef and noting thename and process ID.

NOTE Stopping a process with extreme prejudice.

In some cases, the process may choose to ignore the polite kill signal,and you will find it still running after you have issued the killcommand correctly. If this happens, you can send a more forceful signal.Enter the following:

$ kill -9 PID

Run ps -ef to confirm that the process has been deleted.

There’s a very small chance that if a process is not even listening for asignal, it will not terminate even when sent a “kill -9 ” signal. In thiscase, the process cannot be killed, and it is usually referred to as a“zombie” process. The only way to make it go away is to reboot.

Page 76: Using HP-UX

76 Chapter 3

Using Your ShellUnderstanding Standard Input, Standard Output, and Standard Error

Understanding Standard Input,Standard Output, and Standard ErrorEach process opens three standard “files”: standard input (stdin ),standard output (stdout ), and standard error (stderr ). Programs usethese as follows:

• Standard input is the place from which the program expects to readits input. By default, processes read stdin from the keyboard.

• Standard output is the place the program writes its output. Bydefault, processes write stdout to the terminal screen.

• Standard error is the place the program writes its error messages.By default, processes write stderr to the terminal screen.

The figure below illustrates the relationship of these files to the process.

Figure 3-1 Standard Input, Standard Output, and Standard Error

Page 77: Using HP-UX

Chapter 3 77

Using Your ShellUnderstanding Standard Input, Standard Output, and Standard Error

Writing Standard Output to a FileThe shell lets you redirect the standard output of a process from thescreen (the default) to a file. Redirecting output lets you store the textgenerated by a command into a file; it's also a convenient way to selectwhich files or devices (such as printers) a program uses.

In its simplest form, the command syntax is as follows:

stdout command > outfile

where command is the command whose output is redirected, and outfileis the name of the file to which the process writes its standard output. Ifthe output file exists, its previous contents are lost. If the file does notexist, it is created.

To append the output to an existing file, use two greater-than signs (>>)pointing to the file to be appended on.

This figure illustrates where stdin , stdout , and stderr go whenoutput is redirected to a file.

Figure 3-2 Standard Input, Output, and Error When Output Is Redirected

Page 78: Using HP-UX

78 Chapter 3

Using Your ShellUnderstanding Standard Input, Standard Output, and Standard Error

The example below shows output redirection using the who command,which displays a list of users currently logged in to the system. Instead ofdisplaying the users on the terminal screen, the output is redirected tothe file whoison .

who(1) $ who > whoison Redirect output to whoison.$ more whoison Display contents of whoison.pat console Oct 9 08:50terry tty01 Oct 9 11:57kim tty02 Oct 9 08:13

Page 79: Using HP-UX

Chapter 3 79

Using Your ShellUnderstanding Standard Input, Standard Output, and Standard Error

Using Files for Standard InputThe shell lets you redirect the standard input of a process so that input isread from a file instead of from the keyboard. To redirect the input of aprocess, separate the command and the input file name with a less-thansign (<) directed at the command name. You can use input redirectionwith any command that accepts input from stdin (your keyboard).

In its simplest form, the command syntax is as follows:

stdin command < infile

where command is the command whose input is redirected, and infile isthe name of the file from which the process reads standard input. The filemust exist for the redirection to succeed.

The figure below illustrates where stdin , stdout , and stderr go wheninput is redirected from a file.

Figure 3-3 Standard Input, Output, and Error When Input Is Redirected

Page 80: Using HP-UX

80 Chapter 3

Using Your ShellUnderstanding Standard Input, Standard Output, and Standard Error

In the following example, standard output from the who command isredirected to a file named savewho . Then, the more command displaysthe contents of savewho . Finally, standard input for the wc (word count)command is redirected to come from the savewho file:

Using “>” $ who > savewho Redirect output to savewhomore savewho Display contents of savewhopat console Oct 9 08:50terry tty01 Oct 9 11:57kim tty02 Oct 9 08:13

Using “<“ $ wc -l < savewho Redirect input from savewho4 The answer

In the preceding example, the wc command with the -l option counts thenumber of lines in the input file. Because input is redirected fromsavewho , this number equals the number of users logged in to thesystem when the who command was executed.

Page 81: Using HP-UX

Chapter 3 81

Using Your ShellUnderstanding Standard Input, Standard Output, and Standard Error

Redirecting Both Standard Input andStandard OutputYou can redirect both the standard input and the standard output of asingle command. However, do not use the same file name for standardinput and standard output, since the original contents of the input fileare lost.

The following figure illustrates where stdin , stdout , and stderr aredirected when both output and input are redirected from and to files.

Figure 3-4 Redirecting Both Input and Output

Page 82: Using HP-UX

82 Chapter 3

Using Your ShellUnderstanding Standard Input, Standard Output, and Standard Error

Using the Default Standard Input and StandardOutputThe following example uses the sort command to sort text typed at thekeyboard. Typing CTRL-D ends standard input. The standard outputdisplays on the terminal screen as follows:

sort(1) $ sortmuffyhappybumpyCTRL- D End of standard input.bumpyhappymuffy End of standard output.

Redirecting Standard InputIn the following example, input is redirected:

$ more socks Display contents of socks.polka dotargyleplaid

$ sort < socks Redirect input from socks and sort the contents.argyleplaidpolka dot

In the preceding example, the sort command uses a file named socksas input. The standard output displays on the terminal screen.

Using Both Standard Input and Standard OutputRedirectionThe next example combines both input and output redirection:

$ sort < socks > sortsocks Use both input and output redirection.$ more sortsocks Display contents of sortsocks.argyleplaidpolka dot

In this example, the sort command reads input from the socks file andwrites output to the sortsocks file; thus, standard output (unlike thefirst two examples) does not display on your screen.

Page 83: Using HP-UX

Chapter 3 83

Using Your ShellUnderstanding Standard Input, Standard Output, and Standard Error

Piping Command Output and InputThe shell lets you connect two or more processes so the standard outputof one process is used as the standard input to another process. Theconnection that joins the processes is a pipe. To pipe the output of oneprocess into another, you separate the commands with a vertical bar (| ).The general syntax for a pipe is as follows:

command1 | command2

where command1 is the command whose standard output is redirectedor piped to another command, and command2 is the command whosestandard input reads the previous command's output. You can combinetwo or more commands into a single pipeline. Each successive commandhas its output piped as input into the next command on the commandline:

command1 | command2 | ... | commandN

In the following example, output from the who command is again storedin the file savewho . Then, the savewho file is used as input to the wccommand:

wc(1) $ who > savewho Redirect output of who to file savewho.$ wc -l < savewho File savewho is input to wc command.4 Sample result.

With a pipeline, these two commands become one:

$ who | wc -l4

As this example illustrates, using pipes eliminates the need fortemporary intermediate files. Instead, the standard output from the firstcommand is sent directly to the second command as its standard input.

Page 84: Using HP-UX

84 Chapter 3

Using Your ShellUnderstanding Standard Input, Standard Output, and Standard Error

Using the tee Command with PipesThe tee command lets you divert a copy of the data passing betweencommands to a file without changing how the pipeline functions. Theexample below uses the who command to determine who is on thesystem. In the example, which is further illustrated in the figure below,the output from who is piped into the tee command, which saves a copyof the output in the file savewho , and passes the unchanged output tothe wc command:

tee(1) $ who | tee savewho | wc -l4$ more savewhopat console Oct 9 08:50terry tty01 Oct 9 11:57kim tty02 Oct 9 08:13

Figure 3-5 Standard Input and Output with Pipes and tee Command

Page 85: Using HP-UX

Chapter 3 85

Using Your ShellUnderstanding Standard Input, Standard Output, and Standard Error

For More Information…HP-UX provides filter programs that are useful in pipelines. Theseprograms accept text as input, transform the text in some way, andproduce text as output. Filter commands include adjust , awk, more ,cut , grep , head , more , pr , rev , sed , sort , spell , and tail . Forinformation on these commands, see their man pages.

Page 86: Using HP-UX

86 Chapter 3

Using Your ShellShell Features: Determining and Changing Your Shell

Shell Features: Determining andChanging Your ShellHP-UX gives you your choice of several different shells. This sectiondiscusses the POSIX and Bourne shells. Details on the C shell can befound in the Shells: User's Guide.

Each of these shells has different characteristics, and you can increasethe speed and efficiency with which you interact with HP-UX if you learnto use some of the built-in features of the shell of your choice.

With the POSIX shell, you can edit your command line and recallprevious commands. Your shell environment can be “customized” usingshell variables and login scripts.

Using simple commands, you can determine which shell you are runningor change your shell temporarily or permanently. See “Determining YourLogin Shell” for a listing of both the file name for each shell and thedefault system prompt.

NOTE Choosing your default shell.

As of the HP-UX 10.0 release, the OSF POSIX Shell replaces the KornShell and Bourne Shell. Thus, /usr/bin/sh will be the POSIX Shell,and /usr/bin/ksh will be linked to /usr/bin/sh . However,/usr/old/bin/sh will contain the Bourne Shell for those users whostill need it.

Page 87: Using HP-UX

Chapter 3 87

Using Your ShellShell Features: Determining and Changing Your Shell

The following table lists features that may help you decide which shell touse:

Table 3-1 Comparison of Shell Features

Features Description POSIXKey Bourne C

Commandhistory

Allows commands to be stored in abuffer, then modified and reused.

Yes No Yes

Line editing Ability to modify the current orprevious command lines with a texteditor.

Yes No No

File namecompletion

Ability to automatically finish typingfile names in command lines.

Yes No Yes

aliascommand

Lets you rename commands,automatically include commandoptions, or abbreviate long commandlines.

Yes No Yes

Restrictedshells

A security feature providing acontrolled environment with limitedcapabilities.

Yes Yes No

Job control Tools for tracking and accessingprocesses that run in thebackground.

Yes No Yes

Page 88: Using HP-UX

88 Chapter 3

Using Your ShellShell Features: Determining and Changing Your Shell

Determining Your Login ShellThe command echo $SHELL displays the file name of the shell youentered when you logged in.

$ echo $SHELL/usr/bin/sh

The echo command displays the contents or value of a variable namedSHELL. The SHELL variable contains the name of the file that containsthe shell program that you are running. In this example, it is/usr/bin/sh , the file that contains the code for the POSIX Shell.

The following table lists both the file name of each shell and the defaultsystem prompt. (The superuser prompt for each is #.)

Table 3-2 Shell File Names and Default Prompts

Shell File Name Prompt

POSIX /usr/bin/sh $

C /usr/bin/csh %

Bourne (obsolete) /usr/old/bin/sh $

Korn (replaced byPOSIX shell)

/usr/bin/ksh (linked to/usr/bin/sh )

$

Page 89: Using HP-UX

Chapter 3 89

Using Your ShellShell Features: Determining and Changing Your Shell

Temporarily Changing Your ShellUnless you are in a restricted shell, you can temporarily change yourshell by using this command:

shell_name

where shell_name is the name of the shell (for example, sh , or csh ).Temporarily changing your shell lets you experiment in other shells. Bytyping the name of the shell you want to run, you invoke (enter) thatshell, and the correct prompt is displayed. To return to your originalshell, type either exit or CTRL-D.

The following example begins in the POSIX Shell, enters the C Shell,and returns to the POSIX Shell:

csh(1) $ csh Enter C Shell.% ps Execute the ps command.

PID TTY TIME COMMAND 6009 tty01 0:00 csh Notice that both the C and

5784 tty01 0:00 sh POSIX Shel l processes are running 6010 tty01 0:00 ps% exit Exit C Shell.$ POSIX Shell returns.

Permanently Changing Your ShellTo permanently change your login shell (the default shell you get whenyou log in), use the chsh (ch ange sh ell) command:

chsh(1) $ chsh username full_shell_name

where username is your user name and shell_path_name is the full pathname (for example, /usr/bin/sh ) of the shell you want as your default.“Determining Your Login Shell” contains the full path names for each ofthe shells. After you use the chsh command, you must log out and log inagain for the change to take effect. For example, if terry changes thedefault login shell to the C Shell, the command reads:

$ chsh terry /usr/bin/csh%

Page 90: Using HP-UX

90 Chapter 3

Using Your ShellEditing the Command Line

Editing the Command LineIn the POSIX shell, you can correct errors in a command line before youenter it, using line editing commands or edit keys. You can also recall aprevious command and edit it. See “Recalling Previous Commands” laterin this chapter.

Using vi Line Editing CommandsChapter 4, “Using the vi Editor,” explains how to use the vi screen editorwith text files. The vi editor is also used to edit command lines.

To enter the vi line editor mode while in the POSIX shell, press ESC tochange from the usual “typing mode” into “edit mode.” Use editingcommands to move the cursor or delete characters. Return to “typingmode” by entering the vi commands i or a to insert or append text.

The following table lists some vi editing commands.

Desired action vi command

Move back one character h

Move forward one character l

Move back one word b

Move forward one word w

Move to the beginning of the line ^

Move to the end of the line $

Delete the character under thecursor x

The editor command set is governed by the setting of the EDITORvariable. Some possibilities are vi or emacs. Setting the EDITORvariable also depends on the VISUAL variable being defined.

To use the vi editor temporarily, type set -o vi . To turn off the viediting mode, type set +o vi . To set the EDITOR variable automaticallyeach time you log in, see “Setting the Login Environment”.

Page 91: Using HP-UX

Chapter 3 91

Using Your ShellEditing the Command Line

An Example of Line Editing with the viCommand SetActivate the vi command set (if it is not already set at login by yourlogin script):

$ set -o vi

Type this next line but do not press Enter :

$ ll /dve | grep '^d' | more

The second element should have been /dev . Correct the error byfollowing these steps:

1. Press ESC. The cursor moves back one space (beneath the e in more ).The line editor is now in “command mode.”

ll /dve | grep '^d' | mor e

2. Press H repeatedly to move the cursor to beneath the v in /dve .

ll /d ve | grep '^d' | more

3. Press X. The character v disappears, and the rest of the line shifts onespace to the left to fill in. The cursor is now under the e in /de .

ll /de | grep '^d' | more

4. Press A. The cursor moves one space to the right. The line editor isnow ready to “append” text to the line.

ll /de _ | grep '^d' | more

5. Press V. The character v is inserted after /de , completing thecorrection.

ll /dev | grep '^d' | more

6. Press Enter to execute the command line.

Page 92: Using HP-UX

92 Chapter 3

Using Your ShellRecalling Previous Commands

Recalling Previous CommandsThe POSIX shell stores the commands you execute in a commandhistory. You can retrieve these commands, modify them, and re-executethem. For information on the C Shell implementation of commandhistory, see the Shells: User's Guide.

For example, make sure you are in the POSIX Shell by typing/usr/bin/sh

Execute some commands, as a test. Then, to re-execute a previouscommand:

1. Make sure you have set vi as the command line editor (enter set -ovi on the command line for the login session, or make the appropriateentries in your .profile to set and export the EDITOR variable).

2. Press ESC.

3. Then press K repeatedly to scroll back to the previous command thatyou want.

4. Or, press J to scroll forward through the command history list.

5. Once you have found the command you want, you can edit it just as ifit were the current command.

6. You can then execute whatever is on the command line by pressingEnter .

The POSIX Shell “remembers” the last 128 command lines you typed inand can display all or any of them. For example, type in some commands:

$ dateThu Sep 8 15:01:51 MDT 1994$ pwd/home/terry$ hostnamehpabc

Page 93: Using HP-UX

Chapter 3 93

Using Your ShellRecalling Previous Commands

Now type in this command:

$ history -3121 date122 pwd123 hostname124 history -3

Notice that the POSIX Shell displays the last three commands (date ,pwd, and hostname ) and the history -3 command. You can increasethe amount of the command history shown by using a larger negativenumber to follow history . For example, this will display the last 100commands if there are 100 commands in the history:

$ history -100 | more

If there are fewer than 100 commands in the history, the full contents ofthe history will be displayed. The output of history is piped to the morecommand so you can see one screenful of the history commands at atime.

For More Information…For more details on the command history in the POSIX Shell, see therelevant tutorial in the Shells: User's Guide. For more information on theKey Shell, see Appendix D, “The Key Shell.”

Briefer presentations are available in the sh-posix, keysh, and csh entriesin the respective man pages.

Page 94: Using HP-UX

94 Chapter 3

Using Your ShellSetting the Login Environment

Setting the Login EnvironmentWhen you log in, your shell automatically defines a unique workingenvironment for you, which is maintained until you log out. Yourenvironment defines such characteristics as who you are, where you areworking, and what processes you are running. These characteristics aredefined by values assigned to environment variables.

Your shell environment is analogous to an office environment. In theoffice, physical characteristics like lighting and temperature are similarfor everyone. But many factors in your office environment are unique toyou, such as your routine tasks and your individual workspace. Thus,your work environment is different from that of your co-workers—just asyour shell environment is different from theirs.

The login ProgramWhen you log in, HP-UX runs a program named login . This programstarts your session using data stored in the /etc/passwd file, whichcontains one line for each system user. This file includes your user name,password (in encrypted form), home directory, and the shell to run whenyou log in. If /etc/passwd doesn't specify a shell, the POSIX Shell(/usr/bin/sh ) is selected.

The login program does the following:

• Display the Password: prompt (if you have a password).

• Verify your user name and password in the /etc/passwd file.

• Assign default or user-defined values to the shell environment.

• Start executing the shell process.

Page 95: Using HP-UX

Chapter 3 95

Using Your ShellSetting the Login Environment

Environment VariablesThe shell environment defines how HP-UX interacts with you. Theenvironment's characteristics are defined by environment variables,which consist of a name and a value. For example, the directory in whichyou begin each session is your home directory; its environmentvariable is the variable named HOME, and its value is assigned during thelogin process. Throughout this section, the value of HOME is equal to/home/terry .

Here are some environment variables set during the login process. Notethat most of these will already be set in your default .profile file.

HOME • Defines the user's home directory; the default directory for the cdcommand (for example, /home/terry ).

• Default value assigned during login.

LOGNAME • Contains the user name (for example, terry ).

• Default value is username

MAIL • Determines where the system looks for mail. Set based on the username (for example, /var/mail/terry ).

• Typical default value is /var/mail/ username

PATH • Sets the directories through which the system searches to find andexecute commands.

• Typical default values include the following paths:

/usr/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:/usr/lib

SHELL • Determines which shell to run. Set to the last field in the/etc/passwd file entry for the user logging in. If this field is notdefined, the default value is used.

• Typical default value is /usr/bin/sh

TERM • Specifies the kind of terminal for which output is prepared.

• Typical default value is hp

Page 96: Using HP-UX

96 Chapter 3

Using Your ShellSetting the Login Environment

TZ • Provides the current time zone and difference from Greenwich MeanTime. Set to Mountain Standard Time by default; your systemadministrator should change the value if you are in another timezone. Set by the script /etc/profile .

• Typical default value is MST7MDT

EDITOR • Determines the default editor.

• Typical default value is vi

DISPLAY • Specifies window display host. Use on a remote system to displaywindows locally.

• Typical default value is DISPLAY=:0

Page 97: Using HP-UX

Chapter 3 97

Using Your ShellUsing Login Scripts to Set the System Environment

Using Login Scripts to Set the SystemEnvironmentDuring the login process, HP-UX prompts you for your user name andpassword (if applicable) before displaying a shell prompt. HP-UX alsonotes which shell you have selected to run, starts your shell process, andsets up your environment referring to login scripts. A login script is a filethat lets you customize your environment.

A login script contains commands that let you define your systemenvironment. When you log in, default values are assigned toenvironment variables. Login scripts provide an automatic way tochange the value of these variables every time you begin a session.

Two types of login scripts are used:

• A system script for all users of a particular shell on your system orHP-UX cluster.

• Local login scripts in your own home directory.

Typically, a system administrator maintains the system login scripts.These scripts set up a default environment for everyone on that system.The POSIX shell uses a system login script named /etc/profile .

Once your account is set up, you maintain the local login scripts in yourhome directory. The local scripts allow you to set up an environmentspecific to your needs. The Bourne Shell looks for one script: .profile .The POSIX shell uses two login scripts: .profile and the one referredto by the ENV variable.

Default versions of the login scripts are placed in your home directorywhen your account is set up. Default versions are also in the /etcdirectory. For reference, the default .profile script for the POSIX shellis /etc/skel/.profile .

Why Use Login Scripts?Login scripts provide a convenient way to set up the shell environment tosuit individual needs. For example, the script can change the value of thesearch path used to find commands, change the shell prompt, set theterminal type, or simply cause the shell to greet you with a friendlymessage of your choosing.

Page 98: Using HP-UX

98 Chapter 3

Using Your ShellUsing Login Scripts to Set the System Environment

Customizing your login script is not required, and the login script yoursystem administrator provides should set up the most critical shellparameters.

A Summary of Login ScriptsThe following table summarizes the login scripts for each shell. All thescripts run when you first log in. For more information on the POSIX, C,Key, and Bourne Shells, see the Shells: User's Guide.

Table 3-3 Shells and Their Login Scripts

Shell System Login Script Local Login Script

POSIX /etc/profile $HOME/.profile

C /etc/csh.login $HOME/.cshrc$HOME/.login

Bourne (obsolete) /etc/profile $HOME/.profile

Page 99: Using HP-UX

Chapter 3 99

Using Your ShellSetting and Referencing Variables

Setting and Referencing VariablesYour shell uses both environment variables and shell variables to defineyour environment. Your login shell uses environment variables andpasses them to all processes and subshells that you create. Shellvariables are known only to your current shell and are not passed tosubshells.

$ The POSIX shell sets variables using an assignment statement and anoptional export command. In all shells, you refer to the value of avariable by placing a dollar sign ($) in front of the variable name.

Assigning Values to VariablesIn the POSIX shell, variables are assigned (or set). They can also becreated, if necessary. Both tasks are done with an assignment statement:

name=value

The name is the variable name and value is the value assigned to thevariable. No spaces are allowed between name and = or between = andvalue.

In the following example, the shell prompt (PS1) is reset so that it reads:

Ready ==>

If PS1 is a shell variable, the subshell (created by typing sh ) does notknow the new value. If you export PS1, the value of PS1 passes to thesubshell:

$ PS1="Ready ==> " Set shell variable PS1.Ready ==> sh Type in subshell name.$ exit Subshell now has default prompt; exit to original shell.Ready ==> export PS1 Set environment variable with export.Ready ==> sh Enter subshell.Ready ==> Subshell knows the new value of PS1.

Ready ==> exit Leave the subshell.Ready ==> PS1=”$ “ Set environment variable with export.$ Back to normal.

Page 100: Using HP-UX

100 Chapter 3

Using Your ShellSetting and Referencing Variables

Referencing the Values of Variables(Parameter Substitution)All three shells use parameter substitution for referencing the valueof variables. Parameter substitution means that the variable's value issubstituted for the variable name. Parameter substitution occurs when adollar sign ($) is placed in front of the variable name.

For example, earlier you learned to determine your login shell with thecommand echo $SHELL :

$ echo SHELL Because $ is omitted, the word SHELL is echoed.SHELL$ echo $SHELL The $ is included, so the value of SHELL is echoed./usr/bin/sh

The echo $SHELL command uses parameter substitution. The shellsubstitutes the value of the environment variable named SHELL into theecho command because the dollar sign ($) precedes the variable name.

For More Information…To learn more about parameter substitution, refer to sh, sh-posix, keysh,or csh man pages or to the Shells: User's Guide.

Page 101: Using HP-UX

Chapter 3 101

Using Your ShellFinding Commands with Search Paths

Finding Commands with Search Paths

PATH When you type a command, HP-UX must be able to find the directorycontaining the command before it can run the command. The PATHenvironment variable contains a list of directories you want HP-UX tosearch when looking for commands. Your PATH should contain all thedirectories necessary to locate all the commands that you use.

PATH Variable FormatThe PATH variable is read from your .profile or /etc/profile loginscript. It contains a list of directories to search, separated by colons.There should be no spaces surrounding the colons. You can also use theecho command to determine the current value of PATH, as follows:

$ echo $PATH/usr/bin/sh:/usr/bin:/usr/local/bin

This line means that when you type a command, the shell first searchesfor the command in the /usr/bin/sh directory, in the /usr/bindirectory, and then in the /usr/local/bin directory. If the command isnot found in any of these directories, the shell displays this message:

command_name: Command not found.

Page 102: Using HP-UX

102 Chapter 3

Using Your ShellFinding Commands with Search Paths

Changing PATHIf the shell can't find a command that you know exists, you have twooptions:

1. Type the full path name of the command. For example, if you wish toexecute a command called prog , and it resides in the directory/home/sue/bin , type this:

$ /home/sue/bin/prog

2. Or, change the value of the PATH variable to add the command path, abetter long-term solution if you use the command frequently.

The following table shows the path names of the most frequently useddirectories.

Directory What It Contains

/usr/bin Frequently used HP-UX commands.

/usr/sbin Commands the system administratoruses.

/usr/bin/sh POSIX Shell

/usr/contrib/bin Contributed programs not supportedby Hewlett-Packard.

/usr/local/bin Programs and commands written atyour location.

$HOME/bin A directory you might create for yourown shell scripts and programs.

CAUTION Because of the potential security risk, do not put your current directory(usually represented as . ) as the first element in PATH. Leave thecurrent directory out of your PATH, or include it only as the last element.

Remember that directories in PATH are searched in the order in whichthey appear (left to right). In general, put the most frequently useddirectories first in the path — unless two commands in the search pathhave the same name (for example, /usr/bin/rm and $HOME/bin/rm ).In this example, if you want the shell to find your version of rm first, put$HOME/bin before /usr/bin in PATH.

Page 103: Using HP-UX

Chapter 3 103

Using Your ShellFinding Commands with Search Paths

The following example shows how to alter PATH to include $HOME/binbefore any other directories, and to include the current directory as thelast directory in the search path (this example assumes you're using thePOSIX shell):

$ echo $PATH/usr/bin/sh:/usr/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin$ PATH=$HOME/bin:$PATH:. Including “.” as the last element makes$ echo $PATH the current directory the last one searched./home/terry/bin:/usr/bin/sh:/usr/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:.

Setting PATH as an Environment VariableNormally, you set PATH as a environment variable, so it is set to theappropriate value when you log in. In the Bourne and POSIX shells, youcan change PATH in the .profile script and export it. You can find outmore about these scripts in Shells: User's Guide.

Page 104: Using HP-UX

104 Chapter 3

Using Your ShellSetting Terminal Characteristics

Setting Terminal CharacteristicsFor most effective use of your terminal, HP-UX must know the type ofterminal or graphics display you're using. If no terminal type is provided,the default value is TERM=hp. The tset command sets terminalcharacteristics.

The default local login script prompts you to enter your terminal type asfollows:

TERM = (hp)

Pressing Enter sets the TERM environment variable to hp , the defaultvalue. This value works with Hewlett-Packard terminals, but it may notlet you take full advantage of your terminal or graphics display features.Entering a different value sets the TERM environment variable to thatvalue.

ttytype(1) The ttytype(1) command can be used to help you determine your terminaltype. See the man page for details.

Selecting a Value for the TERM VariableHP-UX supports many terminal types. The/usr/share/lib/terminfo database tells HP-UX how tocommunicate with each terminal type. When you assign a value to TERM,the value must equal a value in the terminfo database.

For example, the files listed under /usr/share/lib/terminfo/2 showall acceptable TERM values that begin with 2 (this is only a partiallisting):

$ ls /usr/share/lib/terminfo/22382 2397a 2621a 2623p 2626-x40 2640a2392 2500 2621k45 2624 2626A 2640b2392A 2621 2621nl 2624a 2626P 26442392a 2621-48 2621nt 2624p 2626a 26452393 2621-ba 2621p 2625 2626p 26472393A 2621-fl 2621wl 2626 2627 2647F

Page 105: Using HP-UX

Chapter 3 105

Using Your ShellSetting Terminal Characteristics

Here are some common terminal and graphics display settings forHewlett-Packard equipment. When more than one choice is listed, allchoices are equivalent.

If You Are Using a .. Set TERM to ..

terminal the terminal's model number; forexample 2622 , hp2622 , 262x , or2392

HP Vectra PC 2392

medium resolution graphicsdisplay (512x600 pixels) 300l or hp300l

high resolution graphics display(1024x768 pixels) 300h or hp300h

HP 98550 display station(1280x1024 pixels) 98550 , hp98550 , 98550a , or

hp98550a

HP 98720 or HP 98721 displaystation (1280x1024 pixels) 98720 , hp98720 , 98720a ,

hp98720a , 98721 , hp98721 ,98721a , or hp98721a

Setting TERM with the tset CommandThe tset command (with the -s option) sets the value of TERM andinitializes your terminal characteristics. If you always log in using thesame terminal type, you may change your .profile to eliminate theTERM prompt. Your .profile contains a line similar to:

eval ` tset -s -Q -m ':?hp' `

This command displays the TERM prompt. To customize the command,replace ?hp with your terminal type.

For example, the following command initializes your terminal as ahigh-resolution graphics display (300h ), but the TERM prompt itself doesnot display:

eval ` tset -s -Q -m ':300h' `

If you use more than one type of terminal (such as one at work and one athome), you can modify your tset command to include multiple terminaltypes. See tset(1) in the HP-UX Reference for more information.

Page 106: Using HP-UX

106 Chapter 3

Using Your ShellChapter Command Summary

Chapter Command SummaryTo Do This… Type This…

Delete (remove) a file interactively rm -i filename

Run several commands on sameline command; command2

Temporarily change to Key Shell /usr/bin/keysh

Find command information online man command_name

See what processes are running ps -ef

Stop a process kill PID

Stop an unresponsive process kill -9 PID

Redirect standard output to a file command > outfile

Append standard output on a file command >> outfile

Redirect input from a file to acommand command < infile

Redirect both standard input andoutput to a file command < infile > outfile

Connect (“pipe” between) twoprocesses command1 | command2

Save command output to a file andsend to another command command1 | tee file | command2

Determine what shell you are in echo $SHELL

Temporarily change to POSIXShell /usr/bin/sh

Temporarily change to C Shell /usr/bin/csh

Permanently change to anothershell chsh username shell_path_name (then log

out and log in again)

Set command-line editor set -o editor_name

Page 107: Using HP-UX

Chapter 3 107

Using Your ShellChapter Command Summary

Edit your command line (onceeditor is set) Press ESC; use vi commands to move

cursor and enter text

Recall a previous command line In vi mode, press ESC; press k

(backwards) or j (forward) to movethrough command history file

Execute a previous command line Press Enter when desired commandline is displayed

Set a variable value VARIABLE_NAME= variable_value

Display PATH setting echo $PATH

Set terminal parameters tset options term_type

Page 108: Using HP-UX

108 Chapter 3

Using Your ShellChapter Command Summary

Page 109: Using HP-UX

109

4 Using the vi Editor

Editing Text The vi (Visual) editor is the default text editor for your HP-UX system.The vi editor is a powerful, versatile editing tool.

The vi editor is included with every HP-UX system and most otherversions of UNIX as well. It is not difficult to learn or use. This chapterwill teach you the basics of it’s operation.

To do this ... See ...

Starting the vi editor page 110

Editing and deleting text page 112

Positioning the cursor page 113

Scrolling through text page 114

Finding text patterns page 115

Replacing characters page 117

Substituting characters page 117

Saving and exiting page 118

Changing your environment page 119

Making the changes permanent page 121

Page 110: Using HP-UX

110 Chapter 4

Using the vi EditorStarting the vi Editor

Starting the vi EditorStart vi by entering the following command at the prompt:

vi(1) $ vi filename

If a file called filename exists, you will see the first screen of that file. If thefile does not exist, it is created, and you will see a blank screen.

For the impatient reader who does not want to read the next eight pagesbefore learning how to exit vi, you will want to know the secret keysequence: Esc :q! which will exit vi and discard the edits you made.

NOTE Alternative editors do exist.

If you do not wish to use vi , you can use the optional, freely availableEmacs editor. Emacs is a widely used public domain editor that providesmany versatile functions. GNU Emacs, and other related software, isavailable from:

Free Software Foundation, Inc.675 Massachusetts AvenueCambridge, MA 02139-3309USA

[email protected]://prep.ai.mit.edu/pub/gnu/GETTING.GNU.SOFTWARE

You can also get information on Emacs from GNU Emacs: UNIX TextEditing and Programming, Addison-Wesley, 1992.

Page 111: Using HP-UX

Chapter 4 111

Using the vi EditorStarting the vi Editor

Command Mode and Text Entry Mode in viThe vi editor has two basic modes for manipulating text:

• Command mode

• Text entry mode

When you enter vi , you will be in command mode until you enter one ofthe text entry codes, such as i or a, which are explained in this section.

In text entry mode, you can backspace and type over text you have justentered (by pressing CTRL-H or Backspace ). But, if you want to movearound otherwise in your text and execute other text manipulationcommands, you will have to press ESC to return to command mode.

If You Make MistakesUse the following procedures to correct mistakes:

• If you type an error while entering text, press Backspace to back upover the error, and then re-type the correct text.

• The u undo command (lowercase u) reverses the last change made toyour text. The U undo command (uppercase U) reverses all thechanges made to a single line since you began editing that line.

• If you type several errors and cannot recover, exit vi without savingthe file, and start over. To do this, press ESC. Then type q! Enter .

CAUTION Save your work often.

While you work in a file, save your changes frequently (every 5 to 10minutes). Regular saving helps you avoid losing your changes if there isa power failure or other accident. See “Saving Your Work and Exiting vi”.

Of course you probably won’t listen to us until you lose a day’s worth ofwork because the electricity went off suddenly. Then you will develop thehabit of frequently saving your work every 5 to 10 minutes.

Page 112: Using HP-UX

112 Chapter 4

Using the vi EditorEntering and Deleting Text

Entering and Deleting TextPress ESC to ensure that vi is in command mode. Then you can executeany of the following commands (among others). The text entrycommands put vi in text mode; the deletion commands do not.

Type This… To Enter Text…

i Preceding the cursor. Everything after cursor moves tothe right.

I Before the first character of the line.

a After the current cursor position. Cursor moves to theright, and text is inserted as with i .

A At the end of the line.

o Open a blank line below cursor for text entry(lowercase o).

O Open a blank line above cursor for text entry(uppercase O).

Type This… To Delete…

x Character highlighted by the cursor. Does not putdocument in text mode.

nx n characters, starting at the cursor.

dw From cursor to beginning of next word or firstpunctuation.

dd Deletes current line.

dG All lines to end of file, including current line.

When you enter commands in vi , letter case (caps or small letters) doesmatter. For example, lowercase i and uppercase I represent twodifferent commands. Therefore, if the cursor doesn't move as it should,make sure the Caps key is not locked on, or see your systemadministrator.

Page 113: Using HP-UX

Chapter 4 113

Using the vi EditorPositioning the Cursor

Positioning the CursorThese keys move the cursor as follows (press ESC first for commandmode):

To Do This… Type This…

Move the cursor right. l or the right arrow key

Move the cursor left. h or the left arrow key

Move the cursor up. k or the up arrow key

Move the cursor down. j or the down arrow key

NOTE Working with Line Numbers:

To move to a specific line, use G, a “goto” command. For example, supposeyou are editing a file and want to go to line 799. You type 799G, and thecursor moves to line 799. Similarly, to go to line 1 of the file, type 1G. Tomove the cursor to the last line, simply type G.

To find the current line number, press CTRL-G; to display line numbersalong the left margin of your file, type :set number .

Page 114: Using HP-UX

114 Chapter 4

Using the vi EditorScrolling through Text

Scrolling through TextTo scroll, press ESC to ensure that you're in command mode, then typethe appropriate key while holding down the CTRL key.

To Scroll… Type This…

Backward to previous screen. CTRL-B

Backward one half screen. CTRL-U

Backward one line. CTRL-Y

Forward to next screen. CTRL-F

Forward one half screen. CTRL-D

Forward one line. CTRL-E

Page 115: Using HP-UX

Chapter 4 115

Using the vi EditorFinding Text Patterns

Finding Text PatternsTo search forward from the current cursor position, use this command:

/ pattern Enter

where pattern represents the specific sequence of characters you want tosearch for.

To search backward from the current cursor position, use this command:

?pattern Enter

When you press Enter , vi searches for the specified pattern and positionsthe cursor at the first character in the pattern sequence. For example, tosearch forward for the word place , type:

/place Enter

If vi finds place , it positions the cursor at the p. To search foradditional occurrences of place , press either n or N:

• n continues searching in the same direction for place .

• N reverses the direction of the pattern search.

If vi does not find the pattern you specified, it displays the followingmessage at the bottom of your screen, and the cursor is not moved:

Pattern not found

Page 116: Using HP-UX

116 Chapter 4

Using the vi EditorFinding Text Patterns

Searching for Special OccurrencesIn the previous example, vi finds any sequence containing the patternplace , including displace , placement , and replaced .

• To find the single word place , type the pattern with a space beforeand after it (the represents a space):

/ place Enter

• To find place occurring only at the beginning of a line, precede thepattern with a caret (^ ):

/^place Enter

• To find place occurring only at the end of a line, follow the patternwith a dollar sign ($):

/place$ Enter

Using “^” To search literally for such a character as a caret (^ ) or a dollar sign ($),precede the character with a backward slash (\ ). The backward slashtells vi to search for a special character.

Using “$” Special characters are those (such as ^ , $ , * , / , and . ) that havespecial functions for vi . For example, a $ normally means “go to the endof the line,” but if the $ is preceded immediately by a \ , the $ is simplyanother ordinary character.

Using “\” For example, /(No \$ money) searches forward for the pattern (No$ money) . The escape character (\ ) immediately preceding the $ tells vito search literally for a dollar sign.

Page 117: Using HP-UX

Chapter 4 117

Using the vi EditorReplacing Characters

Replacing CharactersTo replace a single character of text, press ESC to enter command mode,position the cursor over the character you want to replace, and type rwhile in command mode. Then type the replacement character. The rcommand lets you substitute only one character. After you have replacedthe character, you are back in command mode.

Substituting CharactersTo substitute one or more characters for a single character, type s whilein command mode. Unlike the r command, the s command puts you ininsert mode and lets you substitute more than one character for a singlecharacter.

When you type the s command, a dollar sign ($) appears in place of thecharacter. After you type the desired character (or characters), press ESC.

To substitute for more than one original character, precede the scommand by the number of characters.

Page 118: Using HP-UX

118 Chapter 4

Using the vi EditorSaving Your Work and Exiting vi

Saving Your Work and Exiting viYou can save your work with or without quitting vi . Press ESC to ensurethat vi is in command mode.

To Do This… Type This…

Save without quitting vi :w

Save and quit vi :wq

Quit vi without saving changes :q!

Save under another file name :w filename

Save in an existing file andoverwrite that file :w! filename

To print your files, see “Viewing and Printing Files” in Chapter 2,“Working with Files and Directories.”

Page 119: Using HP-UX

Chapter 4 119

Using the vi EditorUsing Options to Change Your vi Environment

Using Options to Change Your viEnvironmentTo customize vi , you can set (or unset) any of several options. When youenter vi , options are assigned certain default values.

When exiting vi , all options return to the default, so you will need toreset your options each time you enter vi . See the next section for how tomake your options permanent.

To see all your default options, type:

:set all Enter

To change these values, use the :set command:

:set option Enter

where option is the name of the editor option you want to use (see thefollowing table for descriptions of some of these options).

To unset (discontinue) an editor option, type no before the option:

:set no option Enter

Page 120: Using HP-UX

120 Chapter 4

Using the vi EditorUsing Options to Change Your vi Environment

Table 4-1 Editor Options

Option Abbrev. Default Effect When Set

all ~ ~ Lists all editor options on the screen.

autoindent ai noai Begins each new line of text in the samecolumn as the previous line (useful forprogrammers).

ignorecase ic noic Causes vi to ignore uppercase andlowercase during searches.

number nu nonu Numbers each line of text.

readonly ~ noreadonly Enables write protection on the file you areediting. This ensures that you don'taccidentally change or destroy the file'scontents.

showmatch sm nosm Shows the opening parenthesis, brace, orbracket when you type the correspondingclosing parenthesis, brace, or bracket. Thisoption is useful when you are typingmathematical expressions or writingprograms in a language that usesparentheses, braces, or brackets.

showmode ~ noshowmode Displays a message like “INPUT MODE” or“REPLACE MODE” at the bottom of the screenwhenever you are in either of these modes.

wrapmargin wm wm=0 (zero) Changes the right margin. n equals thenumber of spaces in the right margin. Forexample, if you're using an 80-columnterminal, then :set wm=8 sets the rightmargin at column 72.

Page 121: Using HP-UX

Chapter 4 121

Using the vi EditorMaking Your vi Environment Permanent

Making Your vi EnvironmentPermanentTo avoid setting options or defining abbreviations or macros each timeyou enter vi , place all options and definitions you normally use into an.exrc file in your home directory. This file is read automatically eachtime you enter vi and its contents make your customized vienvironment permanent.

To create or change the .exrc file, follow these steps:

1. Type cd at the HP-UX prompt to ensure that you're in your homedirectory; then use vi to create or edit the .exrc file:

$ cd

$ vi .exrc

2. Type the options, word abbreviations, and macros you want to makepermanent (don't precede the commands with a colon).

3. Type :wq to save the text and exit vi .

After creating the .exrc file, you can access it whenever you want tochange your vi environment. Any of the editor options discussed in theprevious section can be placed in this file.

Page 122: Using HP-UX

122 Chapter 4

Using the vi EditorMaking Your vi Environment Permanent

An Example of Changing Your .exrc FileIn “Using Options to Change Your vi Environment”, you saw examples ofsome of the options that change the overall behavior of vi . You can alsomake vi recognize short forms of commonly used expressions by usingab to define an abbreviation.

If you include the following options and abbreviations in your .exrc file:

set wm=8set showmodeab eeg Electrical Engineering

Then you have changed your vi environment so that each time you entervi , you can expect the following:

• The right margin automatically contains eight spaces (changing thedefault from zero), and a carriage return will occur afterapproximately 72 spaces.

• The lower right part of the screen will show “INPUT MODE” whenyou are in any of the text insert modes.

• Whenever you enter eeg , this abbreviation will automatically expandinto the words Electrical Engineering .

For More Information…For more information on this versatile editor, see The Ultimate Guide tothe vi and ex Text Editors.

Page 123: Using HP-UX

Chapter 4 123

Using the vi EditorChapter Command Summary

Chapter Command SummaryTo Do This… Type This…

Enter vi and create or useexisting file. vi file Enter

Insert text before the cursor. i

Append text after the cursor. a

Delete one character. x

Return to command mode. ESC

Move the cursor right. l or right arrow

Move the cursor left. h or left arrow

Move the cursor up. k or up arrow key

Move the cursor down. j or down arrow key

Exit vi without saving changes. :q! Enter

Write (save) the current file. :w

Write the current file and quit(exit) vi . :wq

Write the current file to filename :w filename

Overwrite contents of filename withthe current file. :w! filename

Write lines x through y of currentfile to filename. : x,y w filename (x,y are specific line

numbers or place markers)

Insert contents of filename into thecurrent file. :r filename

Run an HP-UX command while invi :! command

Print the current file (see “Viewingand Printing Files” in Chapter 2,“Working with Files andDirectories.”) :!lp %

Page 124: Using HP-UX

124 Chapter 4

Using the vi EditorChapter Command Summary

Page 125: Using HP-UX

125

5 Using Electronic Mail

e-mail With an electronic mailer program, you can send messages to other userson your system. If your system is configured to a network, such as a localarea network (LAN), you can send mail messages to users on othersystems.

If you are connected to a larger network such as the Internet, you cancommunicate with users world-wide. Consult your system administratorto determine where you can send electronic mail.

To do this ... See ...

Starting the elm mailer page 126

Understanding the main screen page 127

Entering elm commands page 129

Reading your mail page 130

Sending mail to users on your system page 132

Sending mail to users on other systems page 134

Using mail aliases page 136

Replying to messages page 139

Forwarding messages page 141

Saving messages page 143

Deleting messages page 144

Exiting elm page 145

Mailing a directory and contents page 146

Customizing elm page 148

Page 126: Using HP-UX

126 Chapter 5

Using Electronic MailStarting the elm Mailer

Starting the elm Mailer

elm(1) One of the popular HP-UX mailer programs is called elm (the electronicmailer). Other mailers, such as mail , and mailx , are also available.

1. To start the elm mailer, type elm at the system prompt.

$ elm

2. If this is the first time you have started elm , you will be asked twoquestions about creating directories and folders. Answer y (yes) toboth.

3. To get help in elm , press ? at the command prompt.

• For a summary of all of the commands you can use from elm , press? again.

• For help on a particular command, type the first letter of thecommand (for example, press R to get information about thereply command).

Page 127: Using HP-UX

Chapter 5 127

Using Electronic MailUnderstanding the Main Screen

Understanding the Main ScreenThe main screen of elm has several components, shown in the followingillustration.

Figure 5-1 The elm mailer lets you send and receive messages.

The main screen has these elements:

Heading The first line on the screen displaysthe current mailbox, the number ofmessages, and the current elmrevision number.

Date The date when the message was sent.

Message sender The mail address of the person whosent the message.

Number of lines The total number of lines in themessage.

Subject of message A description of the contents of themessage.

Page 128: Using HP-UX

128 Chapter 5

Using Electronic MailUnderstanding the Main Screen

Current message pointer The highlight indicates the currentmessage.

Status field The status or characteristics of eachmessage. The field can be blank, orcontain the following common statuscharacters:

N—new message NU—new urgentmessage D—message is to be deletedM—multi-part message

Message number This is used to specify a message.

Menu This three-line menu at the bottom ofthe screen shows the commandsavailable.

Command prompt In response to the “Command:”prompt, type any of the commands inthe menu.

Page 129: Using HP-UX

Chapter 5 129

Using Electronic MailEntering elm Commands

Entering elm CommandsEven if you are not familiar with mailers, you can easily use elm byfollowing the instructions displayed on each screen.

To enter an elm command, type the first letter (uppercase or lowercase)of the command. Commands in elm are not case-sensitive.

For a summary of elm commands, press ? within elm , then press ? again.

Also see “Chapter Command Summary” at the end of this chapter.

Page 130: Using HP-UX

130 Chapter 5

Using Electronic MailReading Your Mail

Reading Your MailTo read your mail, start elm by typing elm at the command prompt.

If you have mail, elm displays a list of mail messages. You can read thecurrent message or pick a specific message to read. Messages appear in adisplay similar to the following:

Figure 5-2 Elm lists your mail messages.

• To read the current (highlighted) message, press Enter .

(You can configure elm to use a > to indicate the current message. See“Customizing elm”.)

• If the message has multiple parts, indicated by an “M” in the statusfield, press V one or more times to “View” the sub-parts of themessage.

• To advance to the next message, press J.

• To move to the previous one, press K.

• To jump to a specific message in the header, type the number of themessage and press Enter .

CAUTION Use only one mailer at a time.

Problems with system behavior may result if you attempt to use one ofthe other HP-UX mailers, such as mailx , while you are also working inelm .

Page 131: Using HP-UX

Chapter 5 131

Using Electronic MailReading Your Mail

This example shows the output from reading message 1.

Figure 5-3 An example message.

To return to the elm main screen, press Enter .

NOTE Seeing more mail headers:

Only ten message headers appear on the screen at one time. If you havemore than ten messages you can display them as follows:

• To see the next page of message headers, press +.

• To see the previous page, press -.

• To move to the first message in the list, press =.

• To move to the last message in the list, press *.

Page 132: Using HP-UX

132 Chapter 5

Using Electronic MailSending Mail to Users on Your System

Sending Mail to Users on Your SystemOne of the easiest ways to learn how to send a mail message is to sendone to yourself.

1. Start elm by typing elm at the command prompt.

2. To mail a message, press M as the response to “Command:”

Command: m

3. elm responds with a prompt requesting the mail address of therecipient. (To use aliases for recipients, see “Using Mail Aliases”.)

On your local system, your mail address is the same as your username. Type your user name and press Enter . For example:

Send the message to: leslie

To send a message to more than one person, simply specify eachrecipient's name.

Send the message to: mike leslie tj

4. elm then responds with a subject line prompt. Type the subject line ofthe message and press Enter . For example:

Subject of Message: Important Message to Myself

5. elm responds with a prompt for the carbon copies. Type the mailaddresses of any users who should receive a carbon copy of themessage, then press Enter .

In this example, since you're sending a message to yourself, you don'twant to send any additional copies so press Enter .

(continued)

Page 133: Using HP-UX

Chapter 5 133

Using Electronic MailSending Mail to Users on Your System

6. elm brings up a vi editor window. Type the message. For informationabout using the vi editor, see Chapter 4, “Using the vi Editor.”

This screen shows a sample message.

Figure 5-4 An example message.

To configure your workstation to bring up a different editor, see“Customizing elm”.

7. When you are done typing, save the message.

8. After you exit the editor, you will see the following message on thescreen.

Please choose one of the following options by the first character:E)dit message, edit the H)eaders, S)end it, or F)orget it. s

9. To change any of the header information for your message (forexample, to add recipients to the Cc list, change the message subject,or mark the message as Urgent), press H.

10.To send your message, type s

11.After you have sent the mail message, the elm main screen reappearsand displays the message “Mail sent! ”. It might take a few secondsfor the system to deliver the message.

Page 134: Using HP-UX

134 Chapter 5

Using Electronic MailSending Mail to Users on Other Systems

Sending Mail to Users on Other SystemsIf your system is connected to other systems over a LAN (local areanetwork) or other networking facility that supports elm , you can alsosend mail to users on other systems.

Host Names

Every workstation connected over a network has a unique host name(also known as a node name). To send mail to a user on anotherworkstation, you must know the host name of the user's workstation.

This figure shows an example LAN with four workstations connected.The host names are research , market , develop , and sell .

Figure 5-5 Example host names on a network.

To determine your system's host name, use the hostname command.

Figure 5-6 The host name is circled.

Page 135: Using HP-UX

Chapter 5 135

Using Electronic MailSending Mail to Users on Other Systems

Mail Syntax when Mailing to Other SystemsThe general syntax used when mailing to a user on another workstationis either:

user@host simple format

[email protected] Domain naming

host is the host name of the workstation the person is on, and user is theperson's unique user name.

If the user you are sending to is at another organization, the syntax mayalso include that person's organization name (such as ucsd or hp), andthe domain to which the organization belongs (such as edu foreducational institutions, and com for commercial businesses).

Your system administrator can tell you which syntax to use.

Examples

Suppose you want to send mail to user john, who uses the workstationnamed sell. Then, in response to the elm prompt, you would type thefollowing:

john@sell

To send mail to arnie on your workstation, john on the sellworkstation, and leopold on the research workstation, use thefollowing addresses:

arnie john@sell leopold@research

To send mail to mark who works for a university and davidm who worksfor the XYZ company, use the following addresses:

[email protected] [email protected]

In the first part of this example, mark is the user name, hub is thehostname of Mark's workstation, ucsd is the abbreviation for“University of California at San Diego”, and edu is the domain name foreducational institutions. In the second part, davidm is the user name,xyz is the abbreviation for the XYZ Company, and com is the domainname for companies and businesses.

Page 136: Using HP-UX

136 Chapter 5

Using Electronic MailUsing Mail Aliases

Using Mail Aliases

Shortcuts for mailing You can set mail aliases for people you mail to frequently. Aliases areshortcuts that you define so you don't have to type a recipient's completemail address.

elm provides two types of aliases:

User alias For private use. Individual users create and maintaintheir own user aliases. To create user aliases, see“Creating Mail Aliases”.

System alias For use by all users with the same host. The systemadministrator must create and maintain the systemaliases.

Understanding Mail AliasesAliases allow you to send messages to several recipients by specifying asingle name, or to send messages without specifying a complete mailaddress.

For example, for Christine Lawson at mail [email protected] you might create the alias chris . Tosend a message to Christine, you could enter her alias at the To: prompt:

To: chris

elm automatically converts it to the proper address and full name:

To: [email protected] (Christine Lawson)

Here are more example aliases. (These aliases are shown in the formatthat elm uses to store them in the / HomeDirectory/.elm/aliases.textfile. This file is automatically appended to when you create aliases.)

writers = My writing group = john jtl michele ken willa bgfriends = David and Mark = [email protected] [email protected] = Tom Middleton = [email protected]

Thus, sending a message to writers means that john, jtl,michele, ken, willa, and bg on the local system all receive themessage. Sending a message to friends means that [email protected] [email protected] receive the message. Sending a message totom is shorthand for sending to [email protected] .

Page 137: Using HP-UX

Chapter 5 137

Using Electronic MailUsing Mail Aliases

Creating Mail Aliases1. Press A in response to the “Command:” prompt on the elm screen. The

“Alias commands” sub-menu appears.

2. Press M at the “Alias:” prompt to make a new alias.

NOTE TIP for making aliases:

To make an alias for the person who sent the current message, use ainstead of m. This command reads in the sender's address automaticallyin step 5.

3. Enter the desired alias name, and press Enter . For example:

Enter alias name: chris Enter

NOTE TIP for extra aliases:

You can set more than one alias name. For example, if you enter chrisand cl in the example under “Understanding Mail Aliases”, you can useeither alias to send mail to Christine Lawson.

4. Enter the full name at the next prompt, and press Enter .

For example:

Full name for chris: Christine Lawson Enter

5. Enter the address in response to the next prompt, and press Enter .

For example:

Enter address for chris: [email protected] Enter

Then the sub-menu "Alias commands" returns.

6. Press Enter to set the alias. The main screen returns.

Page 138: Using HP-UX

138 Chapter 5

Using Electronic MailUsing Mail Aliases

NOTE TIP for group aliases:

To create an alias for a group of users, enter more than one address. Forexample, if you set:

In step 3 Enter alias name: friends

In step 4 Full name for friends: Incredible Three

In step 5 Enter address for friends: chris, john,alex@market

You can send a message to chris, john, and alex by responding tothe “To:” prompt with:

To: friends Enter

Note that you must make the aliases chris and john before making thegroup alias. If aliases have not been made, you must enter the user's fulladdress, as is done with alex@market .

Listing and Deleting AliasesYou can view your aliases and delete those you no longer need.

1. Press A in response to the “Command:” prompt on the elm screen. The“Alias commands” sub-menu appears.

2. To check the address of a specific alias, press P and enter the aliasname.

3. To list user aliases, press U.

4. To list system aliases, press S.

5. To delete a specific alias, press D and enter the alias name.

6. To return to elm 's main screen, press R or press Enter .

Page 139: Using HP-UX

Chapter 5 139

Using Electronic MailReplying to Messages

Replying to MessagesWhen you receive a message, you may want to reply to it right away.

1. Move the message pointer to highlight the message to which youwant to reply.

2. To reply to just the sender of the message, press R.

Or, to reply to everyone who received the message, press G.

The following message appears at the bottom of the screen.

Command: Reply to message Copy message (y/n)? n

(If you pressed G, “Group reply” appears after “Command:”.)

3. Press Enter if you don't need to include the original message in yourreply.

Press Y if you do need to include it.

4. The bottom part of the screen now appears similar to this:

Command: Reply to message To: charlie (Charlie Pike)

Subject of message: Re: Meeting Schedule Changed!

The “To:” and “Subject of message:” fields are automatically filled in.The “Re:” in front of the subject indicates that the message is a reply.

If the message you are replying to has no subject, “Re: your mail” isused in the subject field.

You can change the subject field by backspacing over it and typing anew subject.

5. elm responds with a prompt for the carbon copies.

Type the mail addresses of any users who should receive a carboncopy of the message, then press Enter .

6. elm brings up a vi editor.

If you chose yes in reply to the “Copy message” prompt, the editor willbe invoked with the original message copied into the editing buffer.elm inserts the default prefix character (>) and a blank at thebeginning of each line of the copied message.

Type an introductory message.

Page 140: Using HP-UX

140 Chapter 5

Using Electronic MailReplying to Messages

For help with using the vi editor, see Chapter 4, “Using the vi Editor.”

To configure your workstation to bring up a different editor, see“Customizing elm”.

7. When you are done typing, save the file.

8. After you exit the editor, you will see the following message on thescreen.

Please choose one of the following options by the first character:E)dit message, edit the H)eaders, S)end it, or F)orget it. s

9. To change any of the header information for your message (forexample, to add recipients to the Cc list, change the message subject,or mark the message as Urgent), press H.

10.To send your message, type s

11.After you have sent the mail message, the elm main screen reappearsand displays the message “Mail sent! ”.

Page 141: Using HP-UX

Chapter 5 141

Using Electronic MailForwarding Messages

Forwarding MessagesYou may receive messages that you want to forward to someone else,with or without adding your own comments.

1. Move the message pointer to the message you want to forward.

2. Press F. The following message appears at the bottom of the screen.

Command: Forward Edit outgoing message (y/n)? y

3. Press N if you don't want to edit the forwarded message.

Press Enter if you do want to edit it.

4. The bottom part of the screen changes to:

Command: Forward Edit outgoing message (y/n)? Yes

Send the message to:

5. Enter the mail address of the person you want to forward themessage to. To use aliases for recipient names, see “Using MailAliases”.

For example, if you enter donesky ,

Command: Forward To: donesky

Subject of message: AI Competition (fwd)

“(fwd)” is attached to the subject automatically. It tells the recipientthat this is a forwarded message.

If the message you are forwarding has no subject, “Forwarded mail” isused in the subject of message field. The subject field can be edited.

6. elm responds with a prompt for the carbon copies.

Type the user addresses of any users who should receive a carboncopy of the message, then press Enter .

7. elm brings up a vi editor window.

If you chose yes in reply to the “Edit outgoing message” prompt, theeditor will be invoked with the original message copied into theediting buffer. elm inserts the default prefix character (>) and a blankat the beginning of each line of the copied message.

8. Type an introductory message.

Page 142: Using HP-UX

142 Chapter 5

Using Electronic MailForwarding Messages

For information about using the vi editor, see Chapter 4, “Using thevi Editor.”

9. When you are done typing, save your file.

10.After you exit the editor, you will see the following message on thescreen.

Please choose one of the following options by the first character:E)dit message, edit the H)eaders, S)end it, or F)orget it. s

11.To change any of the header information for your message (forexample, to add recipients to the Cc list, change the message subject,or mark the message as Urgent), press H.

12.To send your message, type s

13.After you have sent the mail message, the elm main screen reappearsand displays the message “Mail sent! ”.

Page 143: Using HP-UX

Chapter 5 143

Using Electronic MailSaving Messages to a File

Saving Messages to a FileYou may want to save important messages for future reference.

1. To save the current message to a file, at the “Command:” prompt,type:

Command: s

2. The following prompt appears:

Command: Save MessageFile message in: =/ username

• If you press Enter , the message is saved in a file named with thesender's username in the Mail directory in your home directory.

The equal sign (=) is shorthand for / HomeDirectory/Mail .

• To save the message in another file, enter the name of the file (thename you enter replaces =/ username). For example:

Command: Save MessageFile message in: =/oldnews

If the user is Leslie, the current message is saved in the fileoldnews in the /home/leslie/Mail directory. If the oldnewsfile already exists, the message will be appended to the contents ofthe file. If the oldnews file doesn't already exist, it will be created.

3. To save the message in another directory, enter the path name of thedirectory and the name of the file.

For example:

Command: Save MessageFile message in: ~/messages/oldnews

If the user is Leslie, the current message is saved in the file oldnewsin the /home/leslie/messages directory. If the file already exists,the message will be appended to the contents of the file. If theoldnews file doesn't already exist, it will be created.

CAUTION Saved messages automatically deleted.

After you save a message in a file, the message is marked with a D fordeletion. When you exit elm , the message is automatically deleted.

Page 144: Using HP-UX

144 Chapter 5

Using Electronic MailDeleting Mail Messages

Deleting Mail MessagesAfter you have read your mail messages, you may want to delete them.

1. To delete a mail message, highlight the message and press D.

A D appears to the left of the message to show that it is marked fordeletion.

2. To move to the next and previous messages, use J and K.

3. Delete the marked messages at the “Command:” prompt in one of twoways:

• To delete the marked messages and quit elm , press Q. elm will askyou to confirm this action.

• To delete the marked messages without quitting elm, press $.

The following screen shows two messages marked for deletion:

Figure 5-7 Messages are marked with a “D” for deletion.

Page 145: Using HP-UX

Chapter 5 145

Using Electronic MailExiting the elm mailer

Exiting the elm mailerWhen you are in elm , exit by typing Q at the “Command:” prompt.

If you have mail, elm responds as follows:

Command: q Keep mail in incoming mailbox ? (y/n) y

If you press Y or press Enter , any messages in the incoming mailbox willremain there. You will see these messages when you start elm again.

If you press N, messages are stored in your home directory in analternate mailbox, called mbox.

Page 146: Using HP-UX

146 Chapter 5

Using Electronic MailMailing a Directory and Contents

Mailing a Directory and Contents

Multiple files Sometimes you may need to mail multiple files to another user. You canuse the HP-UX shar utility to bundle files and directories into a singledistribution package. You can then use elm to mail the package.

The files can contain any type of data, including executable programsthat otherwise cannot be mailed. The resulting package can be edited, forexample, to add a message at the beginning.

The optional MPower product allows you to send audio, video, and faxmessages through electronic mail.

1. To bundle files, type the following command in a terminal window:

shar(1) $ shar filename > packagename

You can use more than one filename, separated by spaces. The outputof shar appears only on your screen unless you redirect the outputwith > packagename.

For example, to archive all files with a .tag suffix in the currentdirectory in a file called myarchive , type:

$ shar *.tag > myarchive Enter

The asterisk * is a “wildcard” that matches any combination ofcharacters.

2. To unpack a shar package:

• Edit the file and delete any mail headers or messages at the top ofthe file.

• Use the sh command with the package name as follows:

$ sh package

When unpacking, the files and directories in the package arewritten to their original directory path names.

Page 147: Using HP-UX

Chapter 5 147

Using Electronic MailMailing a Directory and Contents

Using Options for Packing FilesYou can also use options with the shar command. For example, in thiscommand:

$ shar -CvZ *.tag > myarchive Enter

The -C option adds a line saying - cut here - before the archive. The-v option lists the file names as they are packaged. The -Z optioncompresses the files so that they require less disk space. For moreinformation on shar options, see shar(1) in the HP-UX Reference.

To pack files from many directories and unpack them into one directory,use the -b option. The original path names are ignored.

For example, the following command packs files from two directories:

$ shar -b /home/ann/list /home/ann/pics/pic.xwd > package Enter

When package is unpacked, list and pic.xwd are placed in thecurrent directory. Without -b , the original directories would be recreatedduring unpacking.

Mailing a Package 1. Start elm by typing elm at the command prompt.

2. Press M to mail a message.

3. Respond to the prompts for recipient, subject, and copies.

4. When the editor window opens, read in the package file.

In vi , press ESC, then type :r filename.

5. Type an introductory message, if desired.

6. When you are done typing, save your file.

7. After you exit the editor, you will see the following message on thescreen.

Please choose one of the following options by the first character:E)dit message, edit the H)eaders, S)end it, or F)orget it. s

8. To change any of the header information for your message (forexample, to add recipients to the Cc list, change the message subject,or mark the message as Urgent), press H.

9. To send your message, type s

10.After you have sent the mail message, the elm main screen reappearsand displays the message “Mail sent! ”.

Page 148: Using HP-UX

148 Chapter 5

Using Electronic MailCustomizing elm

Customizing elm

Set options The elm mailer has different options you can set to make it moreconvenient for you to use. Among features you can change are the menusthat appear on the screen, the printer your mail is sent to, and the orderin which your mail is listed in your mailbox. These are enteredautomatically in the .elm/elmrc file. This file is created by elm andcontains your default settings and customizations.

Using the Options EditorTo start the elm options editor, press O at the elm command prompt:

Command: o

You will see a screen similar to the following:

Figure 5-8 You can configure elm using the options editor.

Page 149: Using HP-UX

Chapter 5 149

Using Electronic MailCustomizing elm

Using the screen, you can change the 12 predefined settings in the.elm/elmrc file. For information on changing other settings, see MailSystems: User's Guide.

1. To select an option to set, type the first letter of the option. Forexample, to change the way messages are sorted, press S.

To get information about a specific option in the option menu, type ?and then type the first letter of the option.

2. Type the new option setting, then press Enter .

3. When you are finished setting options, press > to save your changes.

If you do not save the changes, the .elm/elmrc file will not bechanged and the changes will only apply to the current mail session.

4. Exit the options editor by pressing Enter .

Example: Changing the Order of Your Mail Messages

1. To change the order in which your mail messages are listed in yourmailbox, press S (the first letter of “S)orting criteria”) in the optionseditor.

Command: s

A message indicates how messages are currently sorted. For example:

This sort will order most-recently-sent to least-recently-sent

2. To see different choices for sorting your messages, press the space bar.

3. When you see the method you want, press Enter . For instance, pressEnter when you see:

This sort will order by sender name

4. Press > to save the change.

5. To return to your mailbox, press Enter again. The messages in yourmailbox will now appear in alphabetical order by sender name.

Page 150: Using HP-UX

150 Chapter 5

Using Electronic MailCustomizing elm

Changing the User Level of elmelm provides three user levels:

• Level 0, for beginning users.

• Level 1, for users familiar with elm .

• Level 2, for expert users.

The user level affects:

• Commands displayed in the command menu.

The frequency of use of each command differs with user level. elmconsiders this difference and tailors the command menu for each userlevel.

• The simplicity of the message.

For example, elm displays “To:” instead of “Send the message to:” inthe higher user levels.

• The handling of a message that was aborted (forgotten).

The aborted (forgotten) message is an outgoing message that iscanceled when the “F)orget it” action is taken. In user level 1 or 2, thecanceled message is stored. This allows you to retrieve the messagebefore exiting elm .

To change the default user level (Level 0, beginner) to an advanced userlevel (Level 1 or 2), follow these steps:

1. Press O (letter O, not zero) at the main screen prompt, “Command:”The options editor screen appears.

2. Press U at the “Command:” prompt.

3. Select an advanced user level (1 or 2) by pressing the space bar, thenpress Enter .

4. Save the setting by pressing >.

For more information on using and customizing elm and other mailsystems in HP-UX, see Mail Systems: User's Guide.

Page 151: Using HP-UX

Chapter 5 151

Using Electronic MailChapter Command Summary

Chapter Command SummaryTable 5-1 Elm Commands

To do this elm command… Use…

Delete the messages marked for deletion without quitting. $

Get help on elm commands. ?

Send a command to the shell without leaving elm . !

Set up mail aliases. a

Change the mailbox. c

Mark messages for deletion. d

Forward the current message to another user. f

Send a group reply to all recipients of the original message. g

Move the message pointer to the next message (below). ▼

Move the message pointer to the previous message (above). ▲

Send mail to a specified user or users. m

Set different mail options, including the sorting method formessages, the destination of printed messages, the type ofmenus displayed, and so on.

o

Print messages. (You can change the destination of printedmessages using the o command listed above.)

p

Quit elm with the option of changing the contents of themailbox.

q

Reply to the author of the current message. r

Save a message to a file. s

View sub-parts of multi-part messages. v

Exit elm without making any changes. x

Page 152: Using HP-UX

152 Chapter 5

Using Electronic MailChapter Command Summary

Page 153: Using HP-UX

153

6 Communicating over a Network

Remote computing Sometimes you may need to get a data file that's on another computer, orto work on a computer that's not at your desk.

The easiest way to accomplish these tasks is to use a network. Local areanetworks (LAN) and wide area networks (WAN) allow you to access dataand use information distributed among many computers.

If your system is on a network, you can transfer files to and from othercomputers, log in remotely, and run applications or commands on remotecomputers.

To do this ... See ...

Using HP-UX network services page 154

Using Global networks page 155

Transferring files with ftp page 156

Copying files with rcp page 163

Logging in with rlogin page 169

Running commands with remsh page 172

Page 154: Using HP-UX

154 Chapter 6

Communicating over a NetworkHP-UX Network Services

HP-UX Network ServicesYour HP-UX system can use a variety of networking services to enableyou to transfer copies of files to other computer systems. These servicescan also enable you to log onto remote machines on the network and runcommands and processes remotely.

Remote File Systems: NFSThe HP Network File System (NFS) services allow many systems toshare the same files. Since NFS is independent of the operating system,it can provide data-sharing among heterogeneous systems. Explicit filetransfers across the network are unnecessary. Since access techniquesare transparent, remote file access remains similar to local file access.

For more information about setting up NFS-mounted file systems, askyour system administrator, or see Installing and Administering NFSServices and the Managing Workgroups and Clusters.

Page 155: Using HP-UX

Chapter 6 155

Communicating over a NetworkUsing Global Networks

Using Global NetworksIf your computer has access to a network, you may be able to connect toglobal and national networks. These networks allow you to communicatewith people all over the world by sending electronic mail and readingelectronic bulletin boards.

Here are some of the largest academic and research computer networks:

• The Internet

• BITNET

• JANET

• NFSNET

• USENET

Ask your system administrator to determine if you have access to one ofthese networks.

For information on the Internet, see publications such as The InternetYellow Pages (Osborne), The Internet Navigator (Wiley and Sons), or TheWhole Internet (O'Reilly and Associates). For more general networkinformation, see the User's Dictionary of Computer Networks, an annualpublication of the University of Texas System Office ofTelecommunication Services. This guide provides descriptions ofnetworks, lists of host systems, site contacts, and organizations.

Page 156: Using HP-UX

156 Chapter 6

Communicating over a NetworkTransferring Files Remotely with ftp

Transferring Files Remotely with ftp

ftp(1) The ftp (File Transfer Protocol) program allows you to do the followingtasks:

• Copy files over a network connection between your local system andremote systems.

• Manage files on remote systems for which you have a valid loginaccount.

Some systems are set up to allow anonymous access to “public” files. Thiscapability is referred to as anonymous ftp .

Preparing to Use ftp

hosts(4) • If your system has an /etc/hosts file, the system administratorshould ensure that it contains entries for each remote systems withwhich you will communicate. Each entry contains the followinginformation:

internet_address official_name alias

For example:

15.15.232.18 hpabc.fc.hp.com hpabc

• Have the system administrator for the remote systems arrange togive you a password and an account, or a login to someone else'saccount, so that you can log in on the remote systems. (If the remotesystem allows anonymous ftp , you do not need an account on thatsystem.)

nslookup(1) Instead of a using a local host file, there may be a list of hosts availablethrough the nslookup(1) command.

For example:

$ nslookup hpabc

If nslookup finds the remote system, you should be able to ftp to it.

Page 157: Using HP-UX

Chapter 6 157

Communicating over a NetworkTransferring Files Remotely with ftp

Starting ftp1. To invoke ftp and connect to a remote system in one step, type the

following:

$ ftp remote_hostname Enter

2. ftp confirms the connection with the remote system and prompts youfor a remote login name:

Name (remote_hostname):

3. To log in with the same remote login name as your local login name,just press Enter .

Otherwise, type your login name for that system and press Enter .

To access an anonymous ftp account, use the login name “anonymous”or “ftp”.

4. ftp prompts you for a password:

Password ( remote_hostname):

Type the password associated with your remote login name and pressEnter . For security reasons, the password will not appear on thescreen.

To access an anonymous ftp account, use any non-null password (byconvention, the password should be your e-mail address).

5. ftp confirms this action with a message:

Password required for remote_login_nameUser remote_login_name logged in.

6. To see a list of available commands, press ? at the ftp> prompt.

To get help on a particular command, press ? and type the commandname.

Page 158: Using HP-UX

158 Chapter 6

Communicating over a NetworkTransferring Files Remotely with ftp

Listing and Creating DirectoriesWhile connected to a remote computer with ftp , you can view thecontents of directories and move between directories.

If the remote computer has been configured correctly, you can also createand remove directories.

To do this… Type…

Display the name of the current remoteworking directory

pwd

Display the name of the current localworking directory

!pwd

Change the working directory on theremote system to remote_directory

cd remote_directory

Change the working directory on thelocal system to local_directory

lcd local_directory

List the contents of the current remotedirectory

ls

Create a remote directory mkdir remote_directory

Delete an empty remote directory rmdir remote_directory

Delete a remote file delete remote_file

Page 159: Using HP-UX

Chapter 6 159

Communicating over a NetworkTransferring Files Remotely with ftp

Transferring Files from a Remote SystemUse get to transfer files from a remote system to your local directory.

1. If you are going to transfer binary files, such as graphics orexecutable programs, type bin at the ftp> prompt.

2. At the ftp> prompt, type:

ftp> get remote_file local_file Enter

The remote_file can be the name of a file in the remote workingdirectory, or a relative or absolute path from that directory.

If you do not specify local_file, the local destination file name will bethe same as the remote source file name.

a. ftp copies the remote file to the local file name.

b. If the remote file is not in the current working directory on theremote system, remote_file is the absolute path name or relativepath name for that file. In that case, ftp copies the file to a filename with the same path on your local system.

c. If there is no matching path, ftp gives you a message, “No suchfile or directory ”.

d. If the destination file already exists, ftp overwrites its contentswith the contents of the remote file.

3. During a successful copy, ftp displays messages confirming the copyand the length of time required.

Page 160: Using HP-UX

160 Chapter 6

Communicating over a NetworkTransferring Files Remotely with ftp

Example

This example shows user leslie getting the remote file special from theremote directory /home/ftp/pub and placing it on the local system asnew_info.

Figure 6-1 Use ftp to get files from remote systems.

Page 161: Using HP-UX

Chapter 6 161

Communicating over a NetworkTransferring Files Remotely with ftp

Transferring Files to a Remote SystemUse put to transfer files from your local system to a remote system.

1. If you are going to transfer binary files, such as graphics orexecutable programs, type bin at the ftp> prompt.

2. At the ftp> prompt, type:

ftp> put local_file remote_file Enter

The local_file can be the name of a file in the local workingdirectory, or a relative or absolute path from that directory.

If you do not specify remote_file, the remote destination file name willbe the same as the local source file name.

a. ftp copies the local file to the remote file name.

b. If the remote file is not in the current working directory on theremote system, remote_file is the absolute path name or relativepath name for that file.

c. If the destination file already exists, ftp overwrites its contentswith the contents of the local file.

3. During a successful copy, ftp displays messages confirming the copyand the length of time required.

Page 162: Using HP-UX

162 Chapter 6

Communicating over a NetworkTransferring Files Remotely with ftp

Example

This example shows user leslie putting the local file new_info onto theremote system as the file special in the remote directory /home/ftp/pub.

Figure 6-2 Use ftp to put files on remote systems.

Exiting ftpTo close the connection with the remote system and exit ftp , type:

ftp> bye Enter

Page 163: Using HP-UX

Chapter 6 163

Communicating over a NetworkCopying Files Remotely with rcp

Copying Files Remotely with rcpYou can use the HP-UX rcp (Remote Copy) command to copy files ordirectories to and from a remote system or to copy among remotesystems.

Preparing to Use rcpIf your system administrator has already configured your system to useremsh , you can use rcp without any additional setup.

To use rcp , you will need the following:

• Read permission on the files you want to copy, and read and search(execute) permission on all directories in the directory path.

• An account (login) on the remote system.

rhosts(4) A .rhosts file in the remote system's home directory containingthe names of your local system and your local login name.

For example, an entry in the .rhosts file on the remote systemmight be:

hpabc leslie

where hpabc is the name of your local system and leslie is yourlocal login name. This allows leslie on hpabc to copy files back andforth to the remote system containing the .rhosts file.

Page 164: Using HP-UX

164 Chapter 6

Communicating over a NetworkCopying Files Remotely with rcp

NOTE It is important to protect your remote .rhosts file and home directory toprevent unauthorized users from gaining rcp access to your remoteaccount.

• Make sure you own the file.

• Make sure that you (the owner ) have read and write permission onthe .rhosts file, and that group and other have no permissions.

• Protect your remote home directory so that owner has read, write,and execute permission, group has read and execute permission,and other only has execute permission.

For information on file ownership and permissions, see “Protecting YourFiles and Directories” in Chapter 7, “Making Your System Secure.”

• A .rhosts file on your local system. This contains the names of allthe systems you will copy files to and from.

For example:

hpqrs lesliehpxyz leslie

• If your system has an /etc/hosts file, the system administratorshould ensure that it contains entries for the remote hosts with whichyou will communicate.

The /etc/hosts file has a line containing the following informationabout each remote system:

internet_address official_name alias

For example:

15.15.232.18 hpabc.fc.hp.com hpabc

Instead of a using a local host file, there may be a list of hostsavailable through the nslookup(1) command.

For example:

$ nslookup hpabc

If nslookup finds the remote system, you should be able to rcp to it.

Page 165: Using HP-UX

Chapter 6 165

Communicating over a NetworkCopying Files Remotely with rcp

Copying Files to a Remote SystemTo copy from your system to a remote system, use the following:

rcp(1) rcp local_file remote_hostname: remote_file Enter

Note that, if local_file is not in your current directory, you will need tosupply the relative path (from your current directory) or the absolutepath name (from / ), in addition to the local file name.

Specify the complete (absolute) path for the remote_file onremote_hostname only if you want to place it in a directory other than theremote home directory.

Examples

To copy myfile from your current directory to a remote system calledhpxyz:

rcp myfile hpxyz:/home/leslie/otherdir Enter

In this case, myfile will be copied as myfile into the remotesubdirectory, otherdir . If you had only supplied the remote host name,rcp would have copied myfile into the remote home directory, also asmyfile .

You can also include a file name in the destination. For example, to copyto a system named hpxyz :

rcp myfile hpxyz:/home/leslie/otherfile Enter

In this case, you have copied myfile as otherfile , in the remotedirectory leslie .

Page 166: Using HP-UX

166 Chapter 6

Communicating over a NetworkCopying Files Remotely with rcp

Copying Files from a Remote SystemTo copy a file from a remote system into your local directory, use thefollowing syntax:

rcp remote_hostname: remote_file local_file Enter

Example

To copy myfile from your account in a remote system hpxyz into yourcurrent directory:

rcp hpxyz:/home/leslie/myfile . Enter

The dot (. ) is shorthand for “current directory”. In this case, myfile willbe copied from the remote directory into your current directory asmyfile .

If you want to copy the file to a new name, supply the destination filename.

If you want to copy myfile into another directory in your home system,use a path name, absolute or relative, as shown:

rcp hpxyz:/home/leslie/myfile otherdir/ Enter

Or, if you want to copy the file to another file name in another directory:

rcp hpxyz:/home/leslie/myfile otherdir/otherfile Enter

Page 167: Using HP-UX

Chapter 6 167

Communicating over a NetworkCopying Files Remotely with rcp

Copying Directories to a Remote SystemTo copy a local directory with all its files and subdirectories to a remotesystem, use rcp with the -r (recursive) option.

The syntax is as follows:

rcp -r local_dir remote_hostname: remote_dir Enter

If local_dir is not in your current directory, you will need to supply therelative path name (from your current directory) or the absolute pathname (from / , the top of the directory hierarchy), in addition to the localdirectory name. Also, if remote_dir is not in your home directory, theremote_dir will require a relative path (from your home directory) or anabsolute path (from / ).

For more information, see “Specifying Files and Directories” in Chapter2, “Working with Files and Directories.”

Example

To copy an entire subdirectory called work to a directory called productsin your home directory on a remote computer called hpabc, type thefollowing:

rcp -r work hpabc:/home/leslie/products Enter

This command creates a directory named work , with all its contents, inhpabc:/home/leslie/products (provided that/home/leslie/products already exists on hpabc ).

The example assumes that you are in the local directory containingwork . Otherwise, you would have to give a relative or absolute path tothat directory, such as /home/leslie/work .

Page 168: Using HP-UX

168 Chapter 6

Communicating over a NetworkCopying Files Remotely with rcp

Copying Directories from a Remote SystemTo copy a remote directory with all its files and subdirectories to a localdirectory, use rcp with the -r (recursive) option in the following syntax:

rcp -r remote_hostname: remote_dir local_dir Enter

Example

To copy a remote directory called work to your current directory, type thefollowing:

rcp -r hpabc:/home/leslie/work . Enter

The dot (. ) indicates the current directory. The work directory will becreated in this directory.

Page 169: Using HP-UX

Chapter 6 169

Communicating over a NetworkLogging In to Another Computer with rlogin

Logging In to Another Computer withrloginIf you have an account on a remote system, you can use rlogin to log into that system by supplying your remote login name and password. Youcan then work on that system, running commands and applications justas you would on your home system.

Preparing to Use rloginNote that if your system has already been configured to use rcp orremsh , you can use rlogin without any additional setup.

• To use rlogin , you will need an account (login) on the remotesystem.

• If your system has an /etc/hosts file, the system administratorshould ensure that it contains entries for the remote systems withwhich you will communicate.

The /etc/hosts file has a line containing the following informationabout each remote system:

internet_address official_name alias

For example:

15.15.232.18 hpabc.fc.hp.com hpabc

Instead of a using a local host file, there may be a list of hostsavailable through the nslookup(1) command.

For example:

$ nslookup hpabc

If nslookup finds the remote system, you should be able to access it.

Page 170: Using HP-UX

170 Chapter 6

Communicating over a NetworkLogging In to Another Computer with rlogin

Logging In on a Remote System1. Type this command:

rlogin(1) rlogin remote_hostname Enter

The remote_hostname is the name of an appropriately configuredremote system. This system is named in your /etc/hosts file.

To log in as another user on the remote system, use the -l usernameoption. By default, you log in with the same user name you are loggedin with on your local system. This option is useful if you are usingsomeone else's computer and want to log back in to your own system.

For example, the following command lets user leslie log in toremote system hpabc from a local system where another user isalready logged in.

rlogin hpabc -l leslie Enter

2. Enter your remote password.

The remote system logs you in with the login message and the remoteprompt.

If you make an error in entering your password, the remote system givesyou the error message, Login incorrect , and prompts you for yourlogin and password again.

Logging Out and Exiting the Remote SystemYou can log out of the remote system just as you would from your homesystem, by typing:

exit Enter

Typing CTRL-D also logs you out on most system.

At this point you are logged out of the remote system, disconnected, andreturned to HP-UX on your local system, which displays a message andyour local prompt:

Connection closed.$

Page 171: Using HP-UX

Chapter 6 171

Communicating over a NetworkLogging In to Another Computer with rlogin

Temporarily Returning to Your Local SystemTo execute a command on your local system while you are in rlogin ,type the rlogin escape character (normally a ~) followed by ! and thecommand to execute locally. (The “~” will be invisible until you type the“! ” after it.) After the command has executed, rlogin returns you to theremote system.

Example

To print the current working directory on your local system while loggedin on a remote system, use the following command. In this case, thecurrent local directory is /home/leslie.

~! pwd Enter/home/leslie[Returning to remote]

Press Enter , or enter a command to redisplay the remote system prompt.

Page 172: Using HP-UX

172 Chapter 6

Communicating over a NetworkRunning a Command Remotely with remsh

Running a Command Remotely withremshThe remsh command enables you to execute a command on a remotesystem without logging in to that system.

Preparing to Use remshThe remote system must be configured as follows:

• You must have an account on the remote system with the same loginname as your local login name.

• The name of your local system and your local login name must be in a.rhosts file in your home directory on the remote system.

NOTE A / HomeDirectory/.rhosts file creates a significant security risk.

It is important to protect your remote .rhosts file and home directory toprevent unauthorized users from gaining rcp access to your remoteaccount.

• Make sure you own the file.

• Make sure that you (owner ) have read and write permission on the.rhosts file, and that group and other have no permissions.

• Protect your remote home directory so that owner has read, write,and execute permission, group has read and execute permission,and other only has execute permission.

See “Protecting Your Files and Directories” in Chapter 7, “Making YourSystem Secure.” for information on permissions.

For example, if your local system's name were hpabc.hp.com and yourlocal login name were jim , you would create on the remote system a/ HomeDirectory/.rhosts file with the following entry:

hpabc.hp.com jim

See the Using Internet Services manual for more details on using andconfiguring remsh .

Page 173: Using HP-UX

Chapter 6 173

Communicating over a NetworkRunning a Command Remotely with remsh

Running a Command Remotely

NOTE Do not use remsh to run an interactive command, such as vi or more .With some interactive commands, remsh hangs. To run interactivecommands, log into the remote system with rlogin .

At your HP-UX prompt, enter:

remsh(1) remsh remote_hostname command Enter

where remote_hostname is the name or alias of a remote system andcommand is a command to execute on the remote system.

X Window You can also set remsh to display the windowed command output on yourlocal system.

At your HP-UX prompt, enter:

remsh remote_hostname command -display system:display.screen

where:

remote_hostname The name or alias of a remote system.

command The program you want to run on theremote system.

system:display.screen The system and display the resultsare to be displayed on. screen isoptional.

Examples

To copy the file special to the file special.old in your home directory onhpabc, use this command:

remsh hpabc cp special special.old Enter

remsh executes the command on the remote system, and then your localsystem redisplays its prompt.

To run xload on the remote system named there and direct outputback to your system, here , use this command:

remsh there -n /usr/bin/X11/xload -display here:0 & Enter

The -n option closes the standard input and prevents remsh from usinginput not intended for it.

Page 174: Using HP-UX

174 Chapter 6

Communicating over a NetworkChapter Command Summary

Chapter Command SummaryTable 6-1 Networking Commands

To Do This… Type This…

Start ftp and connect toremote_hostname

ftp remote_hostname

Get help in ftp ? or ? command

Copy files from remote_hostnameto current directory, in ftp

get remote_file

Copy files from your local currentdirectory to the current directoryon remote_hostname in ftp

put local_file

List the contents of the currentremote directory

ls

Change the current remotedirectory to remote_dir

cd remote_dir

Change the current local directoryto local_dir

lcd local_dir

Exit ftp bye

Copy local_file to a remote system,using rcp , with full path names.

rcp local_file remote_hostname: remote_file

Copy a file from a remote system toyour local directory, using rcp ,with full path names.

rcp remote_hostname: remote_file local_file

Copy a directory structure fromyour local system to a remotesystem

rcp -r local_dir remote_hostname: remote_dir

Copy a directory structure from aremote system to your local system

rcp -r remote_hostname: remote_dir local_dir

Log in on a remote system rlogin remote_hostname

Page 175: Using HP-UX

Chapter 6 175

Communicating over a NetworkChapter Command Summary

Set the display to a local system DISPLAY=hostname:0 ; export DISPLAY

Exit rlogin exit

Run a command on a remotesystem

remsh remote_hostname command

List the contents of a remote homedirectory

remsh hostname ls

To Do This… Type This…

Page 176: Using HP-UX

176 Chapter 6

Communicating over a NetworkChapter Command Summary

Page 177: Using HP-UX

177

7 Making Your System Secure

Security Policy HP-UX provides many security features to protect files fromunauthorized access. Although the system administrator is primarilyresponsible for the security of your system, you need to follow goodsecurity practices to maintain security on your system. The degree towhich you need to enforce security measures depends on where youwork, the security policy in your workplace, and the type of informationwith which you work.

NOTE About Trusted Systems.

Your HP-UX system can be configured as a C2-level trusted system, asdescribed in Section 2.2 of the Department of Defense Trusted ComputerSystem Evaluation Criteria, DOD 5200.28-STD, December 1985.

Your system administrator can inform you if your system is a trustedsystem. When appropriately configured as a trusted system, HP-UXprovides additional security features such as discretionary access controland system auditing.

To do this ... See ...

Security strategies page 178

Securing your terminal page 179

Choosing a secure password page 180

Protecting your files and directories page 183

Changing file or directory ownership page 188

Changing who has access to files page 189

Changing who has access to directories page 191

Controlling default access permissions page 192

Understanding privileged groups page 195

Understanding trusted system access control page 196

Obtaining Software Security Patches page 200

Page 178: Using HP-UX

178 Chapter 7

Making Your System SecureSecurity Strategies

Security StrategiesThis chapter summarizes the security strategies you should follow tohelp keep your system secure:

• Become familiar with the security policies of your workplace.

• Keep your terminal secure.

• Choose a secure password, and protect your password after you havechosen it.

• Be aware of who has permission to access your files and directories,and be able to control such access.

NOTE Security requires ongoing attention.

It may be impossible to have a 100% secure system under allcircumstances. This chapter provides some guidelines for securing yoursystem. However, even these cannot guarantee you a completely securesystem.

Page 179: Using HP-UX

Chapter 7 179

Making Your System SecureSecuring Your Terminal

Securing Your TerminalWhen you are working with sensitive material, take care to position yourterminal so the screen is not visible to others. Never leave your terminalunattended. Log off (exit ) when you leave your terminal.

Guidelines for Securing Your TerminalWhen working with sensitive material, take these security precautions:

• Position your terminal so the screen points away from open windowsand doors.

• Never leave your terminal in a non-secure state:

• Exercise care when logging in. Make sure no unauthorized personis observing you while you're entering your password.

• Log off if you will be away from your terminal for a time.

• Clear your display, even if you leave your terminal for a briefperiod. Type clear at the command line prompt. (Note that theclear command clears only the current screen; one can still scrollup and see previous screens.)

NOTE Other security requirements.

Check the security policies in your workplace. You may be required to logoff whenever you leave your terminal, even if only for a brief period.

Working in an Audited EnvironmentHP-UX provides the capability to audit computer use, both on anindividual and system-wide basis. Depending on how your system isconfigured, your actions may be recorded by an audit program. Thissubsystem monitors user actions at your terminal and recordssecurity-relevant information.

Page 180: Using HP-UX

180 Chapter 7

Making Your System SecureChoosing a Secure Password

Choosing a Secure PasswordWhen you choose a password, you want to ensure that no one can guesswhat you chose. If someone knows your password, that person may log inand access your files. This section offers suggestions on how to select andprotect your password. These guidelines are of particular significance ifyou work with sensitive material.

What is a Secure Password?When selecting a password in a secure environment, follow theseguidelines:

• Choose a password that is not publicly associated with you (yourpersonal or professional life, your hobbies, and the like):

• Don't use your name, your spouse's name, your children's names,or your pets' names.

• Don't use the name of your street or your car.

• Don't use phone numbers or special dates (anniversaries,birthdays, and the like).

• Don't use your address, social security number, or license platenumbers.

• Choose a password that is not listed in the dictionary (spelled eitherforwards or backwards). Password-cracking programs can usedictionary lists.

Page 181: Using HP-UX

Chapter 7 181

Making Your System SecureChoosing a Secure Password

What can you use as a password? Here are a few suggestions:

• Make up a nonsense word.

• Make up an acronym.

• Misspell a word intentionally.

• String together syllables from a favorite song or poem.

NOTE Password requirements.

HP-UX requires that your password be six to eight characters long. Atleast two of these characters must be letters (uppercase or lowercase); atleast one character must be either a numeral (the digits 0 through 9) or aspecial character (such as - , _, or $).

See “Changing Your Password” in Chapter 1, “Getting Started,” for someexamples.

Trusted System PasswordsOn a trusted system, the system administrator controls how passwordsare generated. The following options are available:

• User-generated passwords: You select your own password butpasswords are run through a screening program that checks thepassword against the dictionary, a list of login names, login namepermutations, repeated characters, and palindromes.

• System-generated passwords using letters only: The system assignspasswords using alphabetical characters only.

• System-generated passwords using a combination of letters,numbers, and punctuation characters: The system assigns passwordsusing alphanumeric and punctuation characters.

• System-generated passwords using pronounceable English phrases:The system assigns passwords that you can pronounce.

NOTE Trusted System passwords can be up to 80 characters long.

Page 182: Using HP-UX

182 Chapter 7

Making Your System SecureChoosing a Secure Password

Protecting Your PasswordWhen you have chosen your password, follow these guidelines to ensurethat no one discovers it:

• Never write down your password.

• Don't tell others your password.

• Don't let others watch as you type your password.

• Don't store your password in the function keys of a terminal.

• Change your password occasionally (for example, once every three orfour months).

See “Changing Your Password” in Chapter 1, “Getting Started,”if youneed information on how to change your password.

• If you use more than one computer, use a different password for eachsystem.

You should always report any changes in status and any suspectedsecurity violations to your system administrator.

Page 183: Using HP-UX

Chapter 7 183

Making Your System SecureProtecting Your Files and Directories

Protecting Your Files and DirectoriesThree classes of users can access files and directories: owner, group, andother. For each of these classes of users, there are three types of accesspermissions: read, write, and execute.

Who Has Access?The three classes of users are:

• Owner — Usually the person who created the file.

• Group — Several users that have been grouped together by thesystem administrator. For example, the members of a departmentmight belong to the same group.

• Other — All other users on the system.

What Kind of Access?The access permissions on a file or directory specify how it can beaccessed by the owner, group, and other user classes.

Table 7-1 A Comparison of Permissions for Directories and Files

Permission Means This For a Directory Means This For a File

read (r ) Users can view names of files anddirectories in that directory.

Users can view the contents ofthe file.

write (w) Users can create, rename, or removefiles or directories contained in thatdirectory.

Users can change the contentsof the file.

execute (x ) Users can view the contents of fileswithin the directory, and runcommands, scripts, and programswithin that directory.

Users can execute (run) the file(if it is an executable file orscript) by typing the filename atthe command line prompt.

Page 184: Using HP-UX

184 Chapter 7

Making Your System SecureProtecting Your Files and Directories

You should always be aware of the permissions assigned to your files anddirectories. Check your files and directories periodically to make sureappropriate permissions are assigned. If you find any unfamiliar files inyour directories, report them to the system administrator or securityofficer.

Always carefully consider the permissions you allow on your files anddirectories. Give others access to them only when you have good reasonto do so (if you are working on a group project, for example, your groupmay need access to certain files or directories).

Displaying Access Permissions

ll(1) The ll (long listing) command displays the following information:

• Whether the item is a file or directory.

• The access permissions for each of the three classes of users (owner,group, and other).

• Number of links.

• Name of the owner.

• Name of the group.

• Size in bytes.

• Date and time of last modification. If the time of last modification wasmore than six months ago, the year is substituted for the hour andminute of the modification time.

Page 185: Using HP-UX

Chapter 7 185

Making Your System SecureProtecting Your Files and Directories

Displaying File PermissionsTo see the permissions, owner name, and group name on myfile , forexample, type the following:

$ ll myfile

When you press Enter , you should see something like this:

-rw-r--r-- 1 leslie users 154 Nov 4 10:18 myfile | | | | | |permissions owner group size date file name

The first dash on the left indicates that myfile is a file (if myfile werea directory, you would see a d in place of the dash).

Here is a closer view with all permissions indicated (note that thepermissions are in sets of three):

rwx rwx rwx | | |owner group other

If a permission is not allowed, a dash appears in place of the letter. In theexample above (-rw-r--r --), owner (leslie ) has read and writepermission (rw- ); group (users ) and other have only read permission(r-- ).

Page 186: Using HP-UX

186 Chapter 7

Making Your System SecureProtecting Your Files and Directories

Displaying Directory PermissionsTo display permissions showing owner, group, and other for a specificdirectory, use the ll command with the -d option.

For example, to see the permissions on the projects directory below thecurrent directory, type the following:

$ ll -d projects Follow the ll command with a -d and the directory name.

When you press Enter , you should see something like this:

drwxr-x--- 1 leslie users 1032 Nov 28 12:38 projects

The first character (d) in the long listing above indicates that projectsis a directory. The next nine positions (three sets of three) indicate theread (r ), write (w), and search (x ) permissions for owner, group, andother.

If a permission is not allowed, a dash appears in place of the letter. Hereis a closer view with all positions indicated:

d rwx rwx rwx| | | |

directory owner group other

Then, in the original example above (drwxr-x--- ):

The owner (leslie ) has read, write, and search permission (rwx ); group(users ) has read and search permission (r-x ); other has no access (--- )to the projects directory.

Page 187: Using HP-UX

Chapter 7 187

Making Your System SecureProtecting Your Files and Directories

Guidelines for Access to Sensitive FilesMake sure that permissions assigned to sensitive files and directoriesare appropriate. Here are some general suggestions:

• Only you should be able to write to your home directory.

• Only you should be able to write to the files used to customize yourhome environment, for example, .login and .profile (.profileis discussed in Chapter 3, “Using Your Shell,”, in this manual, and inthe Shells: User's Guide).

• Only you (and the pseudo-group “mail”, assigned to the mailer)should be able to write to your mailfile /var/mail/ username.

For More Information…For information on access control lists (ACLs), which allow finer controlof access to files, see the acl(5) man page and Managing Systems andWorkgroups.

Page 188: Using HP-UX

188 Chapter 7

Making Your System SecureChanging File or Directory Ownership

Changing File or Directory OwnershipTo change the owner of a file, use the chown (“ch ange owner”) command.The file's owner and the superuser are the only ones who can change afile's permissions.

For example, to give user george ownership of the scores file, use thiscommand:

chown(1) chown george scores

The owner can either be a decimal user ID or a login name found in the/etc/passwd file. You can see the file's current owner by typing llfilename.

NOTE You can change both owner and group at the same time.

For example, this command changes both the owner of the file and thegroup to which the file belongs:

chown george:team scores

Page 189: Using HP-UX

Chapter 7 189

Making Your System SecureChanging Who Has Access to Files

Changing Who Has Access to FilesTo change who has read, write and execute permission on your files, usethe chmod (change mode) command. In general, give others access toyour files only when you have good reason to do so (if you are working ina group project, for example, your group may need access to certain files).

Using chmod to Set File PermissionsYou can specify permissions for chmod using the letters u, g, and o, assymbolic code for the owner (“user”), group, and others (the class). This“symbolic mode” is easy to remember, since the symbols r , w, and x (themode) are used directly as arguments in the command.

The chmod syntax uses the +, - , and = signs. The syntax is:

chmod class[ ±=] mode,[ ... ] filename

For example, you can use the symbolic mode to create rw-r--r --permissions by specifying the symbols rw , r , and r directly in the chmodcommand. “User” is represented by u, “group” by g, and “other” by o. Toassign the permissions absolutely, use the = sign in the argument.Unspaced commas separate class permissions:

chmod u=rw,g=r,o=r myfile

When permissions are being set the same, you can also combine thearguments as:

chmod ugo=r myfile

With only read permission on myfile , no one can write to it. Also, if younow try to remove myfile , the rm command asks you whether you reallywant to remove the file:

rm myfilemyfile: 444 mode? (y/n) n If you do not want to remove it, enter n.

If you do want to remove it, enter y.

To create rw------- permissions and set “no permissions” for theclasses g and o, use = with no symbol following:

chmod u=rw,g=,o= filename

Permissions are added with the + sign. Again, separate eachclass-permission with a comma and no space:

chmod u+rw,g+r,o+r filename

Page 190: Using HP-UX

190 Chapter 7

Making Your System SecureChanging Who Has Access to Files

You can also subtract permissions from u, g, or o, using - , to restrict thelevel of permission from a previous “higher” level. For example, if youhad set rwxrw-rw- and you wanted to change this to rwx------ :

$ chmod g-rw,o-rw filename

However, unless you began with no permissions you may find that using+ or - has added to, or subtracted from, some previously existingpermissions for that file. Run the ll command to check this. If in doubt,set the permissions absolutely by using =.

Later, if you want to permit yourself and members of your group to readfrom and write to myfile , use chmod as follows:

$ chmod ug=rw,o=r myfile

The ll command now should show:

-rw-rw-r-- 1 leslie users 154 Nov 4 10:18 myfile

Here is a summary of the various chmod commands you can use toprotect myfile .

To Set Permissions so that… Type This…

Only you can read from myfile ,and no one (including you) canwrite to it. Set permissions to-r-------- . chmod u=r,g=,o= myfile

Everyone can read from myfile ,but no one can write to it. Setpermissions to -r--r--r . chmod ugo=r myfile

Only you can write to myfile , buteveryone can read it. Setpermissions to -rw-r--r-- . chmod u=rw,go=r myfile

Only you and members of yourgroup can write to myfile , buteveryone can read it. Setpermissions to -rw-rw-r-- chmod ug=rw,o=r myfile

Everyone can read from or write tomyfile . Set permissions to-rw-rw-rw- . chmod ugo=rw myfile

Only you can read from or write tomyfile , but no one else can. Setpermissions to -rw- ------ chmod u=rw,go= myfile

Page 191: Using HP-UX

Chapter 7 191

Making Your System SecureChanging Who Has Access to Directories

Changing Who Has Access to DirectoriesIn addition to changing permissions on files, the chmod command canalso change permissions on directories. For example, you can protect adirectory so that no one can alter its files.

The following examples assume that the directory projects existsunder your current working directory.

To Set Permissions to… Type This…

Allow other users to list and accessthe files in projects , but not tocreate or remove files from it. Setpermissions to drwxr-xr-x . chmod u=rwx,go=rx projects

Allow all users to list, create,remove, and access files inprojects . Set permissions todrwxrwxrwx . chmod ugo=rwx projects

Allow only yourself to list, create,remove, and access files inprojects . Set permissions todrwx------ . chmod u=rwx,go=- projects

When determining who should be allowed to use your directories, beaware that anyone who can write to a directory also can remove orrename a file in that directory — even if that person cannot write to thefile.

For More Information…This section covered some of the most common uses of the chmodcommand for protecting files and directories. To learn more about chmod,see the chmod(1) man page.

Page 192: Using HP-UX

192 Chapter 7

Making Your System SecureControlling Default Access Permissions

Controlling Default Access PermissionsIn the previous two sections, you learned how to change the permissionson individual files and directories using the chmod command. You shouldalso be aware of the default permissions assigned to all of your files anddirectories at the time you create them. You can list or change thedefault permission settings by using the umask command.

umask(1) Default file permissions are assigned by the system whenever you createa new file or directory, and these are governed by your umask setting.The default umask setting is 0, which means that new files are createdwith read/write permission for everyone (-rw-rw-rw- ) and newdirectories are created with read/write/search permission for everyone(drwxrwxrwx ).

To restrict these default permissions for newly-created files anddirectories, use the umask command.

When a new file is created, each bit in the file mode creation mask that isset causes the corresponding permission bit in the file mode to be cleared(disabled); hence the term mask. Conversely, bits that are cleared in themask allow the corresponding file mode bits to be enabled in newlycreated files.

The umask command built into the POSIX and Key shells acceptssymbolic mask values (as well as the obsolescent numeric form). Thesesymbolic mask values are similar to those used with the chmodcommand (see chmod(1)).

Page 193: Using HP-UX

Chapter 7 193

Making Your System SecureControlling Default Access Permissions

umask syntax is as follows:

umask who operator permissions

where the parameters have the following meaning:

who One, two, or all of the following characters:

• u (for user permissions)

• g (for group permissions)

• o (for other permissions)

• a (short form for ugo )

If the who character is omitted, operator andpermissions apply to all categories (same as a or ugo ).

operator One of the characters +, - , or =.

• + means clear the file mode bits represented by theaccompanying who and permissions values in themask, thus enabling corresponding permissions innewly created files.

• - means set the file mode bits represented by thespecified who and permissions values in the mask,thus denying corresponding permissions in newlycreated files.

• = means clear the file mode bits specified by thecorresponding who and permissions values and setall others.

permissions One of the characters or character combinations r , w, x ,rx , wx, rw , or rwx , specifying read, write, and/orexecute (search) permission for the corresponding whoand operator.

If permissions is not specified, no change is made to theexisting file creation mode mask for the correspondingwho.

Page 194: Using HP-UX

194 Chapter 7

Making Your System SecureControlling Default Access Permissions

For example, to set the umask value to produce read, write, and executepermissions for the file's owner and read-only permission for all others(-rwxr--r-- ) on newly created files, you would enter this:

$ umask u=rwx,g=r,o=r

To set the umask value to produce read, and write permissions for thefile's owner, read-only for users in the same group, and no access forothers (-rw-r------- ), enter the following:

umask a-rwx,u+rw,g+r

To determine your current umask setting, type:

$ umask -S

NOTE Don’t lock yourself out.

You should not set a umask value that restricts your access permissionsto your own files. A number of HP-UX utilities, such as vi , assume thatyou can always access newly-created files. Such files might include thetemporary files that vi creates. These utilities may malfunction whenused under such a restrictive umask setting.

If you set umask at a shell prompt, it will apply to shells and subshells inthe current login session only. It won't apply to future login sessions. Toapply a umask setting automatically at login, add the umask command toyour .profile (POSIX and Bourne Shell users) or .login file (C Shellusers).

For More Information…For more information about the umask command, see the umask(1) manpage.

To learn more about the .profile and .login files, see the Shells:User's Guide.

Page 195: Using HP-UX

Chapter 7 195

Making Your System SecurePrivileged Groups

Privileged GroupsA “privilege” is the ability to ignore access restrictions and changerestrictions imposed by security policy and implemented in an accesscontrol mechanism. On HP-UX, only superusers and members of certaingroups are the only privileged users.

The system administrator can associate a group with a system capabilityso that members of certain groups can be granted special privileges.These groups are called “privileged groups.”

setprivgrp(1) All users by default are members of the CHOWN privilege group. Peoplewith this privilege can change the ownership of files you own. Yoursystem administrator may limit access to the chown(1) command bysetting up privileged groups using setprivgrp(1M). In that case, onlythose in the privileged group or groups can change file ownership usingchown(1). Refer to the chown(1) man page for more information.

getprivgrp(1) Your system administrator can tell you what type of privileges you havebeen granted. You can also execute the getprivgrp(1) command todetermine the special attributes for groups to which you belong:

$ getprivgrp [groupname]

where the optional groupname is the name of the group for which youwant to determine your special attributes. If omitted, the command liststhe access privileges for all privileged groups to which you belong. Referto the getprivgrp(1) man page for more information.

Page 196: Using HP-UX

196 Chapter 7

Making Your System SecureTrusted System Access Control

Trusted System Access ControlIf you are running a C2-level trusted system, there are additional formsof access control you can apply to files and directories.

Using discretionary access control (DAC), owners of objects containingdata can allow or deny access to these objects at their own discretion, ona need-to-know basis. Objects are things such as files, devices, orinterprocess communications mechanisms that another user’s process oryour process is attempting to access. The controls are discretionary inthe sense that a subject with a certain access permission is capable ofpassing that permission to any other subject.

On a standard HP-UX system, you can protect objects, such as files, byestablishing read, write, and access permissions to these objects. If youare the owner, you can set permissions on objects so that your access isdifferent from other group members; group members can have differentaccess to an object than the rest of the user community. The owner canchange these protection attributes so they are more restrictive(controlled access) or more permissive (open access).

You can use the chown and chmod commands to control file and directoryaccess. For more information, refer to the chown(1) and chmod(1) onlineman pages. To learn how to change your current group selection, referalso to the newgrp(1) man page. The newgrp command changes yourgroup ID without changing your user ID and replaces your current shellwith a new one.

On a C2-level trusted system, you can have additional discretionarycontrols on an object that let you include or exclude access even tospecific users. You control who (that is, users or groups of users) hasaccess to files and directories by assigning optional access control lists(ACL) permissions.

Realize that the system administrator can use the su(1) command tobecome another user without logging out. The system administrator orsuperuser can access all files and perform any task on the system. So fileaccess is not restricted for system administrators. Refer to the su(1) manpage for more information.

Page 197: Using HP-UX

Chapter 7 197

Making Your System SecureTrusted System Access Control

Access Control ListsAccess control lists are key to enforcing discretionary access control ontrusted systems. ACLs offer a greater degree of selectivity than HP-UXpermission bits.

An access control list is a set of user, group, and mode entries associatedwith a file that specify permissions for all possible user ID or group IDcombinations.

acl(5) Refer to the acl(5) online man page for detailed information about accesscontrol lists and definitions of related security terminology.

Listing ACLsTo see who can access certain files and directories and what permissionsare allowed, you can use the lsacl command:

$ lsacl filename

The system responds with a listing in this general form:

(user.group,mode) ... filename

where (user.group,mode) is an ACL entry and filename is the name of thefile or directory for which you want a listing.

For example:

$ lsacl filex(sarah.adm,rw-) (alex.%,r--) (%.mtg,r--) (%.%,---) xfile

where:

(sarah.adm,rw-) means user sarah in group adm has read and writepermissions (rw-) on filex.

(alex.%,r--) means user alex in any group (%) has read permission (r--) onfilex.

(%.mtg,r--) means any user (%) in the group mtg has read permission r--)on filex.

(%.%,---) means no other user from any other group has read, write orexecute permission on filex.

Page 198: Using HP-UX

198 Chapter 7

Making Your System SecureTrusted System Access Control

Changing ACLsBy adding entries to access control lists, you can allow or deny access toparticular users or groups of users. You can set or change ACLs using thechacl command.

The general form of the chacl command is as follows:

$ chacl ‘user.group operator mode’ filename

where:

user is the login name; a % here means all users.group is the user’s group; a % here means all groups.operator is +, -, or = to add, deny, or specify permissions to existing ACLentries.mode indicates the permissions allowed (that is, r for read, w for write,and x for execute/search.filename is the name of the file or directory for which you want to specifyaccess.

For example:

$ chacl ‘cyc.%=rw’ myfile

Creates a new ACL entry allowing the user cyc in any group (%) read andwrite (=rw) access to myfile.

$ chacl ‘%.%+r’ status

Modifies an ACL entry to allow all users(%) in all groups (%) read access(+r) to the file status.

Refer to the chacl(1) man page for more information and examples ofsetting ACLs.

Additional Notes about ACLsIf a file contains ACLs and you use the chmod command to change filemode access permissions without using the -A option, you will delete anyoptional entries in the file’s ACL.

Trying to delete a base ACL entry will result in no access to a file.

Only the fbackup (1M) and frecover(1M) file archive utilities handleACLs correctly. Archive programs such as ar(1), cpio(1), ftio(1), tar(1),and dump(1M) are unable to handle ACLs on files with optional ACLentries.

Page 199: Using HP-UX

Chapter 7 199

Making Your System SecureTrusted System Access Control

Backing Up and Recovering Files with ACLsOn a trusted system, you should only use fbackup(1M) and frecover(1M)to back up and recover files selectively. These commands retain ACLsthat have been applied to the files. Your system administrator can helpwith the authorized copying of files to tape or disk. It is likely you willhave to get permission to use the tape drive or other media and you willneed to get the name of the device.

Realize that you need to keep copied files in a safe location. Label tapesand disks. Make sure the files are copied with the correct accesspermissions if you load them onto another system.

Refer to the fbackup(1M) and frecover(1M) online man pages for moreinformation.

The command tar(1) needs to be used properly to ensure that the DACpermissions are preserved when coping files to and from tape. Be sure touse the -p when taring files from a tape to your system in order topreserve DAC permissions. See the tar(1) man page for moreinformation.

Removable Media SecurityIt is your responsibility to protect the physical security of removablemedia such as floppy disks and tapes. Do not leave them lying around. Itis best to keep them locked up since it is easy for other people to readwhat you have on these media.

Page 200: Using HP-UX

200 Chapter 7

Making Your System SecureObtaining Software Security Patches

Obtaining Software Security PatchesThe U.S. Computer Security Act of 1987 stipulates that if financial lossoccurs due to computer fraud or abuse, the company, not the perpetrator,is liable for damages.

To protect system and data integrity, HP recommends that you establisha comprehensive security policy to govern computer use. HP providesup-to-date software patches to close known security problems that allowunauthorized root access to your system.

For information on available HP-UX security patches, contact HPsupport at:

[email protected]

or access the World-Wide Web (WWW) using a web browser with thisURL:

http://us-support.external.hp.com

or, for Europe,

http://europe-support.external.hp.com

In addition to HP support options, you can explore on you own at the HPweb sites:

http://www.hp.com

and

http://www.software.hp.com

Page 201: Using HP-UX

Chapter 7 201

Making Your System SecureChapter Command Summary

Chapter Command SummaryTo Do This… Type This…

Display access permissions of filesand directories. ll

Add or subtract accesspermissions. chmod class±permissions name

Change access permissionsabsolutely. chmod class=permissions name

View current mask setting. umask -S

Change permissions mask setting. umask who operator permissions

Page 202: Using HP-UX

202 Chapter 7

Making Your System SecureChapter Command Summary

Page 203: Using HP-UX

203

A HP-UX Quick Reference

How to use this Reference:The following table summarizes the most useful HP-UX commands. Tomake it easier to refer to selected commands, copy or tear out thesepages and place them near your display.

1. Type the commands as they are shown in the second column below.

2. Include paths with file names, if you are working with differentdirectories.

3. Follow each command with Enter .

4. To get more information on a specific command, type:man command_name .

To Do This… Type This…

Working with Directories

Show current working directory pwd

Change directory cd directory_path

Change to home directory cd

Create a directory mkdir directory_name

Remove an (empty) directory rmdir directory_name

Working with Files

Read mail elm

List files and directories in current directory ls

List all files or directories, including invisible (“dot”)files

ls -a

List files, and mark directory names with “/ ” lsf

Compress a file compress filename

Page 204: Using HP-UX

204 Appendix A

HP-UX Quick ReferenceHow to use this Reference:

Uncompress a file uncompress filename

Create or edit a file vi file_name

Display file contents more file_name (q to quit)

Display the first 10 lines of a file head file_name

Display the last 10 lines of a file tail file_name

Copy a file cp file_name file_copy

Move a file to a new file name mv old_file new_file

Append file1 onto the end of file2 cat file1 >> file2

Remove file rm file

Remove a directory dir_name and all its files rm -rf dir_name

Check the spelling in a file spell file_name

Printing

Print a file lp file_name

Determine printer status lpstat -t

Cancel a print request cancel request_id

Finding and Organizing

Find file(s) beginning with x in current andsubdirectories

find . -name ' x* '

Find all occurrences of word in all files in currentdirectory

grep word *

Sort listfile alphabetically sort listfile

Display date and time date

List all command aliases alias

Find HP-UX command information man command_name

Determine PATH setting echo $PATH

To Do This… Type This…

Page 205: Using HP-UX

Appendix A 205

HP-UX Quick ReferenceHow to use this Reference:

Determine what shell you're in echo $SHELL

Security Operations

Create or change password passwd

Display permissions for a file ll file_name

Display permissions for a directory ll -d directory_name

Change file or directory permissions chmod class=permissionsname

Change file or directory ownership chown user name

System Operations

Clear screen clear

Set command-line editor set -o editor_name

Edit your command line (in Korn/Key/Posix Shell setfor vi )

ESC (use vi commands)

Recall previous command line (with vi editor) ESC k (back) or j (forward)

Execute previous command line Enter (when line is displayed)

Set terminal type (select term_type from/usr/lib/terminfo )

TERM=term_type

List current process status and PIDs ps -ef

Kill (terminate) a process kill PID

Create or change a password passwd

Redirect input from a file to a command command < infile

Connect two processes with a “pipe” command1 | command2

To Do This… Type This…

Page 206: Using HP-UX

206 Appendix A

HP-UX Quick ReferenceHow to use this Reference:

Page 207: Using HP-UX

207

B Doing Advanced HP-UX Tasks

For advanced usersOccasionally you may need to perform more advanced configuration orsystem administration tasks. These tasks frequently require superuserpermission and a more advanced knowledge of HP-UX. To run SAM,ensure you have superuser permission, then enter /usr/sbin/sam onthe command line.

The following tables list advanced tasks for HP-UX, and providereferences to additional information.

Table B-1 Advanced HP-UX Tasks

Task Where to Look

System Administration Tasks

Using SAM, the SystemAdministration Manager.

See the Managing Systems and Workgroups manual. Youcan also run SAM and look at the extensive online helpavailable in SAM.

Getting information onsystem performance.

Run SAM, select and open “Process Management”, thenselect and open “Performance Monitors”, then select andopen one of the available performance tools.

Displaying disk usage. See the du(1) man page.

Recovering disk space. Run SAM, select and open “Routine Tasks”, then select andopen “Selective File Removal”.

Rebooting a system. See the Managing Systems and Workgroups manual.

Changing the system runlevel.

See the Managing Systems and Workgroups manual.

Command Usage Tasks

Running a command at aspecified time

See the crontab(1) man page. You can also run SAM, selectand open “Process Management”, then select and open“Scheduled Cron Jobs”, then select “Add” from the “Actions”menu.

Page 208: Using HP-UX

208 Appendix B

Doing Advanced HP-UX TasksFor advanced users

Network Tasks

Using a remote file system(NFS)

See the manuals Managing Systems and Workgroups andInstalling and Administering NFS Services.

Installing or updating from anetwork server.

See the Installing HP-UX 11.0 manual.

File Tasks

Backing up files ordirectories.

See the Managing Systems and Workgroups manual. Youcan also run SAM, select and open “Backup and Recovery”,then select and open either “Automated Backups” or“Interactive Backup and Recovery” and enter theappropriate information (see SAM online help for morespecific information).

Restoring files or directories. See the Managing Systems and Workgroups manual. Youcan also run SAM, select and open “Backup and Recovery”,then select and open “Interactive Backup and Recovery”,then choose “Recover Files and Directories” from the“Actions” menu.

Printer and Peripheral Tasks

Getting information onprinters.

See the lpstat(1) man page. You can also run SAM, selectand open “Printers and Plotters”, then select and open“Printers and Plotters”.

Enabling or disabling aprinter.

Run SAM, select and open “Printers and Plotters”, thenselect and open “Printers and Plotters” again, highlight oneof the printers listed, then choose the appropriate actionfrom the “Actions” menu.

Adding or removing printers See the Managing Systems and Workgroups manual. Youcan also run SAM, select and open “Printers and Plotters”,then select and open “Printers and Plotters” again,highlight one of the printers listed, then choose theappropriate action from the “Actions” menu.

Task Where to Look

Page 209: Using HP-UX

Appendix B 209

Doing Advanced HP-UX TasksFor advanced users

Diagnosing a printing error See the Managing Systems and Workgroups manual. Youcan also run SAM, select and open “Printers and Plotters”,then select and open “Printers and Plotters” again,highlight one of the printers listed, then choose “ShowCommon Problems” from the “Actions” menu.

Selecting system defaultprinter.

See the Managing Systems and Workgroups manual. Youcan also run SAM, select and open “Printers and Plotters”,then select and open “Printers and Plotters” again,highlight one of the printers listed, then choose “Set asSystem Default Destination” from the “Actions” menu.

Adding or removingperipherals.

See the manuals Managing Systems and Workgroups, andConfiguring HP-UX for Peripherals. You can also run SAM,select and open “Peripheral Devices”, then select and openthe appropriate area for the type of peripheral you want toadd.

Configuration Tasks

Modifying login scripts(.profile , .kshrc , etc.).

See the Shells: User's Guide.

Setting and referencingenvironment variables.

See Chapter 3, “Using Your Shell,” in this manual and alsothe Shells: User's Guide.

Modifying or viewing userinformation.

Run SAM, select and open “Accounts for Users andGroups”, then select and open “Users” and use the“Actions” menu to select what you want to do to a useraccount. Also see the Managing Systems and Workgroupsmanual.

Modifying a user's group ID. Run SAM, select and open “Accounts for Users andGroups”, then select and open “Users”, highlight the user,then select “Modify Group Membership” from the “Actions”menu. Also see the Managing Systems and Workgroupsmanual.

Removing a user. Run SAM, select and open “Accounts for Users andGroups”, then select and open “Users”, highlight the user,then select “Remove” from the “Actions” menu.

Task Where to Look

Page 210: Using HP-UX

210 Appendix B

Doing Advanced HP-UX TasksFor advanced users

Page 211: Using HP-UX

211

C Scheduling Commands

Running Commands at Preset TimesScheduling commands are useful if you want to run resource intensivecommands when demands on the system are low or to routinely runcommands at certain times. For example, you can schedule a long file toprint at midnight or erase temporary files in your home directoryeveryday.

at(1) The at command runs commands in your home directory at the time youspecify.

crontab(1) The crontab command runs commands in your home directory atregularly specified intervals.

Prerequisites for Using at and crontabBefore you can use crontab or at, your system administrator must set upcertain files that allow you permission to run these commands.

Two files, called at.allow and at.deny in /usr/lib/cron determinewhether you can use the at command. You can use it if your name is inat.allow .

If at.allow does not exist, the system checks to see if your name is inat.deny . If it is, you are denied access to the at command.

If neither at.allow nor at.deny exists, only those with superuserprivilege can use at . If only at.deny exists and it is empty, all users canuse at .

Permission to use crontab is determined in the same way except thatthe files are called cron.allow and cron.deny .

Refer to the at(1) and crontab(1) man pages for more information.

Page 212: Using HP-UX

212 Appendix C

Scheduling CommandsRunning Commands at Preset Times

Running Commands Using atSuppose you want to print a large file at night when system usage is low.The following at command sequence prints the file “bigfile” at 4:00 AM.

at 4am (Type the at command)

lp bigfile (Enter the command you want to schedule for later.)

Ctrl-D (End the command by pressing Ctrl-D.)

You can also specify a date. For example, to print a message on April 10,at 3:30 AM, use the following commands:

at 3:30am Apr 10

echo “time to go home” > /dev/console

Ctrl-D

To list jobs scheduled with at, enter:

at -l

You will see output such as:

job 8745156.a at wed Sep 17 11:00:00 1997

Submitting Batch Jobs

batch(1) You can also use the batch command to submit a batch file. For example:

$ batch

nroff filename > outfile

Ctrl-D

This command executes an nroff command when the system is able tohandle it. Refer to the at (1) man page for more details.

Page 213: Using HP-UX

Appendix C 213

Scheduling CommandsRunning Commands at Preset Times

Running Commands Using crontabYou can use the crontab command to run commands at regularintervals. For example, you can send a weekly e-mail reminder for ameeting to your mailbox, or erase all “tmp” files everyday.

The crontab command creates a file called by your username in thedirectory /var/spool/cron/crontabs . The commands in the file areexecuted at the specified intervals in your home directory.

A crontab file contains line with six fields each separated by spaces ortabs. The first five fields specify the time the command will be run

minute (0-59)hour (0-23)date of the month (1-31)month of the year (1-12)day of the week (0-6 with 0=Sunday)

The sixth field is a string that is executed at the appropriate time.

To create a crontab command file, enter:

$ crontab

Then type the commands you want to schedule and press Ctrl-D .

30 8 * * 4 echo “Staff meeting today at 10:00 AM”0 0 * * * rm *.tmp 2 > errfile

Ctrl-D

The crontab file is interpreted as follows:

On Thursday at 8:30 AM, crontab sends you a reminder of your 10:00AM staff meeting. The first field (30) indicates 30 minutes after the hour.The second field indicates the hour (8). The asterisks mean all legalvalues. The 4 means Thursday.

At midnight everyday, crontab erases files with a *.tmp extension in yourdirectory. Error messages are redirected to a file called errmsg in yourhome directory.

List crontab To list your current crontab entries, use the -l option.

$ crontab -l

Refer to the crontab(1) man page for more information.

Page 214: Using HP-UX

214 Appendix C

Scheduling CommandsRunning Commands at Preset Times

Page 215: Using HP-UX

215

D The Key Shell

Using the Key Shell

keysh(1) An optional “friendlier” shell is available for users who want analternative to using a regular shell. The Key Shell uses softkey menusand context-sensitive help to assist with command options and syntax.The Key Shell automatically translates softkey commands into HP-UXcommands when the Enter key is pressed.

Using the Key Shell DisplaysThe Key Shell gives you softkey displays at the bottom of your screenthat provide a “menu” of basic shell commands, along with their optionsin sequence. To start Key Shell, enter the command /usr/bin/keysh .(Exit this shell by entering: exit .) You will first see a status line like thefollowing

Figure D-1 Key Shell Softkey Display

You can enter commands from the Key Shell softkey menu or you canenter standard HP-UX commands as usual. If you enter standard HP-UXcommands, the Key Shell will often display an appropriate left-to-rightset of menu options in the softkey label area at the bottom of your screen.Each label corresponds to a softkey, f1 through f8. The softkeys areseparated into groups of four. You may select any or none of the optionssuccessively by pressing the corresponding softkey.

When you want to see more commands, or more options to go with acommand you have already chosen, press the More softkey, f8. This willcause the Key Shell to display the next “bank” of softkeys in sequence,eventually cycling back to the first, if you press f8 repeatedly.

After you make a selection by pressing a softkey, your choice will appearon the command line in “English,” just as it appeared in the softkeydisplay, with the correct order and spacing.

Page 216: Using HP-UX

216 Appendix D

The Key ShellUsing the Key Shell

Example: Entering a Command with the KeyShellFor example, enter the ls command. You will see the following:

Figure D-2 Options Displayed

Many softkey commands require that the user enter a parameter orselect an additional softkey before pressing Enter . A “prompt line”underneath the command line will indicate whether you need to enteranything else.

If you select ls , and then select the “sorted” option, the Key Shell willask you to specify how you want your file listing sorted:

Figure D-3 Required Options Requested

At any time, you can use the Help softkey, f1, to find out more about whatfunctions are available to you.

Suppose you have selected “newest-oldest” for the sort option above.You can now enter the finished command line by pressing Enter . Or, if youwant to preview the HP-UX commands to which these “English” wordscorrespond, you can optionally press Insert

line and the HP-UX commands will be displayed as shown in the figurebelow.

Figure D-4 Optional HP-UX Commands Display

Page 217: Using HP-UX

Appendix D 217

The Key ShellUsing the Key Shell

Customizing Your Key Shell SoftkeysYou can change the Key Shell's configuration (for example, status line oroptions) using the Keysh_config softkey in the “More 4 of 4” display. Anychanges you make will be automatically saved in the .keyshrc file inyour home directory. This file will then be replayed upon subsequentinvocations of keysh .

If they are not already on, some global options that you can change usingKeysh_config are:

To Enable Enter These Softkeys and Press Enter

Help softkey Keysh_config options help on

Automatic prompt messages Keysh_config options prompts on

Visible HP-UX commandtranslations Keysh_config options translations on

To turn off any of these options, enter off at the end of the entry sequenceinstead of on.

Status line indicators you can change, using the Keysh_config softkey,are:

To Enable Enter These Softkeys and Press Enter

Host name Keysh_config status_line host_name on

User name Keysh_config status_line user_name on

Currentdirectory Keysh_config status_line current_dir on

Mail status Keysh_config status_line mail_status on

Date Keysh_config status_line date on

Time Keysh_config status_line time on

Page 218: Using HP-UX

218 Appendix D

The Key ShellUsing the Key Shell

Summary of Key Shell ProceduresThe general rules for using the Key Shell are:

• Select any desired softkeys from left to right.

• Use the More softkey to see more options.

• Optionally, use the Insert line key to preview the translatedcommand-line.

• Use the Help softkey to find out more functions.

If you make an error, use Backspace or CTRL-H to erase the line back towhere you want to re-enter command text.

You can also use the arrow keys, Clear line , Delete line , Insert char , and Delete

char to manipulate your command line, in addition to using the editorthat is set for your POSIX Shell. Note that Clear line functions to deletethe line only from the cursor position to the end of the line. Delete line ,however, deletes the entire command line and cancels the command.

For more information, see the keysh(1) man page, and the Shells: User'sGuide.

Page 219: Using HP-UX

Glossary 219

Glossary

absolute path name The fullpath name of a file, including allthe directories leading to it,starting with root (/ ) and endingwith the file name itself. Forexample, /home/michael/myfile is an absolute path name.

See also file, file name, pathname, relative path name.

access permissions Filecharacteristics (including read,write, and execute permission)that determine if a process canperform a requested operation onthe file (such as opening a file forwriting).

Hence, access permissions controlwho can read or alter files ordirectories. They define read,write, and execute permissions forthe file's owner, members of thefile's group, and all others.

alias An alternative name for aperson or a list of people, used as ashortcut when sending electronicmail.

For example, if you often send mailto someone whose mail address [email protected] ,you could set up the alias chris .

Then you could send mail just tochris instead of typing the entireaddress.

application See softwareapplication.

argument The part of acommand line that identifies whatelement (file, directory, etc.) is to beacted upon.

background process Aprogram, usually low priority, runnon-interactively by the shellwithout terminal I/O, while otherprocessing occupies the terminal.Place an ampersand (&) at the endof a command line to cause thatcommand to be run as abackground process.

backup A copy of all or part of thefile system.

boot To start up your system,loading it into the computermemory.

Bourne Shell A commandinterpreter. As of the HP-UX 10.0release, the OSF POSIX shellreplaces the Korn Shell andBourne Shell. Thus, /usr/bin/shwill be the POSIX shell. However, /usr/old/bin/sh will still contain theBourne shell.

Page 220: Using HP-UX

220 Glossary

Glossary

CD-ROM Compact Disc Read-Only Memory.

CD ROM file system A read-onlymemory file system on compactdisk. You can read data from a CDROM file system, but you cannotwrite to one.

cluster A group of workstationsconnected via a LAN. Onecomputer, the cluster server,performs as a server to the cluster.It provides file access, login access,file transfer, printing and otherservices across the network to thecluster nodes.

command interpreter Aprogram that reads lines of textfrom standard input (typed at thekeyboard or read from a file), andinterprets them as requests toexecute other programs. An HP-UX command interpreter is calleda "shell".

command line prompt Acommand line prompt shows thatthe computer is ready to acceptyour commands. Each terminalwindow has a command lineprompt that acts just like thecommand line prompt that wouldbe shown if your computer was notrunning HP CDE. Usually thecommand line prompt is %, >, or $.

You can find the command lineprompt by pressing Enter in an HPCDE terminal window.

control key The keyboard key,normally labeled "CTRL", that isused as a modifier key. You holddown this key while pressinganother key.

C Shell An HP-UX commandinterpreter, invoked as csh .

current working directory Thedirectory in which you arecurrently located. Relative pathname searches begin in thisdirectory. It is also called theworking directory.

cursor An image used to indicatethe focus of keyboard input. Thecursor can have several forms. Forinstance, the text entry cursorappears as an I.

directory An organizational unitof your workstation's disk drive,composed of files andsubdirectories. A directory isanalogous to a file foldercontaining letters (text files),which is contained in a filingcabinet (disk).

Page 221: Using HP-UX

Glossary 221

Glossary

environment The set of definedshell variables (some of which arePATH, TERM, SHELL, HOME)that define the conditions underwhich your commands run. Theseconditions can include yourterminal characteristics, homedirectory, and default search path.These variables are set in your.profile .

execute permission Users withexecute permission on a file canexecute (run) the file as a programby typing the file name at thecommand prompt. If the file is adirectory, they can access thedirectory's contents.

file The basic named unit of datastored on disk. See also directory,file name.

file access permissions Filename characteristics (includingread, write, and execute) thatdetermine whether a process canperform a requested operation onthe file (such as opening a file forwriting). Access permissions canbe changed by a chmod(1)command.

file name The name given to aparticular file. See also file,absolute path name, relativepath name, and path name.

file system The organized set offiles and directories on a hard disk.

filter A command, such as cat ,grep , or sort , that reads datafrom the standard input, performsa transformation on the data, andwrites it to the standard output.

font A complete set of characters(letters, digits, and specialcharacters) of one size and onetypeface. "Ten-point, Helvetica,bold" is an example of a font.

foreground process The processoccupying the currently activeterminal I/O, which may be awindow. The shell will not return aprompt until a foreground processhas finished executing.

group An association of userspermitted to access the same set offiles. The members of a group aredefined in the files /etc/passwd ,/etc/group , and /etc/logingroup (if it exists) via anumerical group ID. Users withidentical group IDs are members ofthe same group.

group access list The groupaccess list is a set ofsupplementary group IDs,associated with a process, used indetermining resource accessibility.

Page 222: Using HP-UX

222 Glossary

Glossary

$HOME The value of theenvironment variablerepresenting the home directory.

home directory A personaldirectory where you keep files andadditional subdirectories thatbelong to you. By default, FileManager and Terminal Emulatorwindows are set to your homedirectory when you first openthem.

/HomeDirectory/ Symbolizesyour home directory. Forexample, if your home directory is/home/anna/ , then /HomeDirectory /bitmaps/smile.bm represents /home/anna/bitmaps/smile.bm .

host name The unique identifyingname given to a system in anetwork. There are generallydifferent host name domainsassociated with different networks.Also called node name. Forexample, hpabc .

invisible file name A file name inwhich the first character is a dot(.). Invisible file names are notdisplayed by the HP-UX listingcommands such as ls and llunless you use the -a option.

keysh The command for invokinga Key Shell.

Key Shell An HP-UX shell which,as an extension of the Korn Shell,uses hierarchical softkey menusand context-sensitive help to aidusers in building command lines.Invoked as usr/bin/keysh .

Korn Shell An HP-UX shell,featuring command history recalland line-editing. Invoked as /usr/bin/ksh . As of the 10.0 Release ofHP-UX, this shell is obsolete,replaced by the POSIX shell.

LANG An NLS environmentvariable used to inform a computerprocess of the user's requirementsfor "native language," "localcustoms," and "coded characterset."

LAN Stands for Local AreaNetwork. The systems and/orclusters that share data, hardware,and software resources vianetworking software.

log in To begin a session on thecomputer by entering thenecessary information, such asyour user name (login name) andpassword.

Page 223: Using HP-UX

Glossary 223

Glossary

login The login name by whichyou are known to the system. Thismay be any group of characters, aslong as it meets system rules.

NFS Network File Services.

NFS file system A file systemaccessible over a network via theNFS Services product.

NLSPATH An NLS environmentvariable used to indicate thesearch path for message catalogs.

operating system The kernel (/stand/vmunix ), commands,input-output control, systemaccounting, mass storage, andother services.

owner The owner of a file isusually the creator of that file.Ownership of a file can be changedby the superuser or the currentowner.

parent directory A directorythat contains other directories,each of which is then called asubdirectory. See alsosubdirectory.

parent process In a shellenvironment, an existing processthat has caused a new process (achild process) to be created.

password An encrypted sequenceof characters used by HP-UX toidentify an authorized user and topermit authorized login on asystem.

path name Specifies the locationof a particular file or directorywithin the directory structure byspecifying the directories you needto pass through to get there. Thedirectory names are separated byslashes. For example, /home/michael/myfile is the pathname for myfile .

There are two kinds of path names.See also relative path namesand absolute path names, andfile name.

permissions See accesspermissions.

PID Process identifier (number).

POSIX POrtable SystemsInterface, complying with UNIXstandards 1003.1 and 1003.2 fromIEEE.

POSIX Shell POSIX-compliantversion of the Korn Shell.

process An invocation of aprogram. Generally, processrefers to a program running in

Page 224: Using HP-UX

224 Glossary

Glossary

memory, while program is thecode (a sequence of instructionsstored on disk that cause thesystem to perform some function).Several users can access the sameprogram simultaneously. Eachgenerates a separate process fromthe same program.

process ID A uniqueidentification number assigned toall processes by the operatingsystem. Also see PID.

prompt See command lineprompt.

read permission Users withread permission can view thecontents of a file or directory.

regular expression A string ofcharacters that selects text.

relative path name The name ofa file, listing all the directoriesleading to that file in relation tothe current working directory.

For example, if you are in the /home directory, michael/myfileis the relative path to /home/michael/myfile .

See also absolute path name.

root See superuser.

root directory The highest leveldirectory of the hierarchical filesystem, from which all other filesbranch. In HP-UX, the slash (/)character refers to the "rootdirectory." The root directory is theonly directory in the file systemthat is its own "parent directory."

run-level The system statedetermined at boot that defines,among other things, multi- orsingle-user status.

SAM The HP SystemAdministration Manager, a toolthat allows you to perform manysystem administration taskswithout having to know thespecific HP-UX commands that areassociated with the task. You musthave superuser permission to runSAM.

server A computer program thatprovides file access, login access,file transfer, printing and otherservices across a network.Sometimes, but not always, aserver consists of a dedicatedcomputer.

session Generally describes thetime between beginning to use anapplication and quitting the

Page 225: Using HP-UX

Glossary 225

Glossary

application. More specifically, usedto describe the time betweenlogging in and logging out.

shell An HP-UX commandinterpreter (Bourne, Korn, Key,POSIX or C), providing a workingenvironment interface for theuser. The shell takes commandinput from the keyboard andinterprets it for the operatingsystem.

software application A programused to perform a particular task,usually interactively, such ascomputer-aided design, textediting, or accounting. StyleManager, Text Editor, and FileManager are examples of softwareapplications.

standard error The destinationof error and special messages froma program, intended to be used fordiagnostic messages. Thestandard error output is oftencalled stderr . Standard errorusually appears on the displayunless it is directed otherwise.

standard input The source ofinput data for a program. Thestandard input file is often calledstdin. Standard input is usuallysupplied by entering data at thekeyboard.

standard output Thedestination of output data from aprogram. The standard output fileis often called stdout . Standardoutput appears on the displayunless it is redirected otherwise.

subdirectory A directory that islocated in, or anywhere on a pathbelow, another directory, which isthen called its parent directory.Sometimes called child directory.

superuser A login that allowsspecial permissions for modifyingsystem files that most users do nothave permission to modify.Superuser is also called "the rootuser" or simply "root" since theuser ID for superuser is root . Onmost computer systems, only a fewusers have permission to becomesuperuser.

System AdministrationManager See SAM.

system administrator Theperson responsible for system andnetwork installation, updating,maintenance, and security at yoursite.

user account The systemadministrator defines a useraccount for every personauthorized to use the system. Each

Page 226: Using HP-UX

226 Glossary

Glossary

user account contains the namethe computer uses to identify theperson (user name) and theperson's password. See also username, password.

user name The name thatidentifies your account to thelogin program and to the mailsystems and other softwarerequiring secure entry. Sometimescalled login.

utility A program provided withthe HP-UX operating system toperform a task, such as printing afile or displaying the contents of adirectory.

working directory See currentworking directory.

write permission Users withwrite permission can change thecontents of a file or directory.

Page 227: Using HP-UX

Index

Index 227

Symbols$HOME/.cshrc, 98$HOME/.login, 98$HOME/.profile, 98.elm directory, 148.exrc file, 121.profile file

modifying, 209.rhosts file, 163/etc directory, 102/etc/hosts file, 156, 164, 169/etc/passwd file, 89, 94/etc/profile script, 97/HomeDirectory/.rhosts, 163/usr/bin directory, 102/usr/bin/sh program, 86, 94/usr/contrib/bin directory, 102/usr/lib directory, 102/usr/local/bin directory, 102/usr/share/lib/terminfo database,

104

Aabsolute path name, 50access control lists, 187, 197access permissions, 183

changing with chmod, 189accessing

directories, 183files, 183sensitive files, 187

ACL, 187adding

peripherals, 209printers, 208

addressmail, 135

advanced tasks, 207alias

creating, 137deleting, 138elm mailer, 136

listing, 138system alias in elm, 136user alias in elm, 136

alias command, 204anonymous ftp, 156appending to a file, 44archive

creating for mailing, 146arguments, command, 72auditing, 179

Bbacking up files or directories,

208backups, 208

restoring, 208backward scrolling in vi, 114backward searching in vi, 115books available, 29

ordering, 29Bourne Shell

features, 86obsolescence, 86

CC Shell

features and informationsource, 86

cal command, 73cancel command

stopping a print job, 40canceling

print request with cancelcommand, 40

cat commandcreating files with, 34terminating input, 34

cd command, 56changing

access to directories withchmod, 191

access to files with chmod, 189

directory with cd command, 56group of file, 188host name, 27IP address, 27owner of files or directories,

188password, 28properties of directory with

chmod, 191properties of file with chmod,

189run level, 207shell, 89time zone, 27user level in elm mailer, 150

checking spellingwith spell command, 204

chmod command, 189, 191chown command, 188chsh command, 89clear command, 179command help, 30command help online

echo, 204man, 204

command history, 92command interpreter, 25command line, 25, 73

editing, 90help, 215help for, 30logging in, 23logging out, 26piping output and input, 83redirecting standard input,

output, error, 76command mode in vi, 111commands

arguments, 72editing command line, 90elm, 129, 151entering with Key Shell, 215line editing, 90

Page 228: Using HP-UX

228 Index

Index

multiple, 73options, 72re-executing in the POSIX

Shell, 92running at specified times, 207running multiple on the same

command line, 73running remotely, 173syntax, 30, 72

commands (by name)alias, 204cal, 73cancel, 40cat, 34, 204cd, 56, 203chmod, 191, 205chown, 188, 205chsh, 89clear, 179, 205compress, 203cp, 42, 59, 204cp -r, 60date, 44, 204diff, 43echo, 88, 100elm, 125, 151, 203exit, 26, 89find, 67, 204ftp, 156get, 159grep, 65, 204head, 39, 204kill, 75, 205ll, 184, 185, 205ll -d, 186, 205lp, 40, 204lpstat, 40lpstat -t, 204ls, 35, 203ls -a, 37, 203lsf, 54, 203man, 30, 204mkdir, 54, 203

more, 38, 204mv, 41, 58, 204mv -i, 41passwd, 205ps, 205put, 161pwd, 48, 203rcp, 163remsh, 172rlogin, 169, 170rm, 42, 204rm -rf, 62, 204rmdir, 61, 203set, 205shar, 146sort, 82, 204spell, 204tail, 39, 204tee, 84TERM, 205tset, 105umask, 192uncompress, 203vi, 203wc, 79who, 77

comparing files, 43compressing files, 203configuring

elm mailer, 148set_parms program, 27

contentsfinding file with grep, 65

copyingdirectory with cp -r command,

60file from remote system, 156,

159, 166file to and from remote

systems, 163file to remote system, 161, 165file with cp command, 42remote directories, 167, 168

correcting errors in commandsKey Shell, 90POSIX Shell, 90

cp command, 42, 59cp -r command, 60creating

directory with mkdircommand, 54

file with cat command, 34mail aliases, 137subdirectory with mkdir

command, 54current directory, 48

changing with cd command, 56security, 102

current message, 130current working directory, 48cursor

positioning in the vi editor, 113customizing

elm mailer, 148

Ddate command, 44deactivating a user, 209default

printer, 209shell prompts, 88

definingmail aliases, 137

deletingdirectory with rmdir command,

61file with rm command, 42mail messages, 144text in vi, 112user accounts, 209

determininglocation in directory hierarchy,

49shell, 88

diff command, 43

Page 229: Using HP-UX

Index

Index 229

differences between files, 43directory

accessing, 183backups, 208changing owner with chown,

188changing who has access to,

191changing with cd command, 56copying files with cp command,

59copying with cp -r command,

60current working, 48deleting with rmdir command,

61hierarchy, 45home, 48listing files in, 45, 52listing with lsf command, 54mailing, 146moving, 58navigating, 48organizing your files, 45ownership, 188parent, 45path names, 50permissions, 183protecting with chmod, 191removing with rmdir

command, 61root (/), 47, 48security, 183, 191subdirectory, 45wildcard characters in

directory names, 63directory hierarchy

determining location, 49disabling a printer, 208disk space

recovering, 207disk usage

displaying, 207

DISPLAY environment variable,95

displayingdisk usage, 207file permissions, 184man pages, 30

documentcreating in vi, 111editing in vi, 112opening in vi, 110saving in vi, 118

documentationavailable, 29ordering, 29

Eecho command, 88, 100editing

command line, 91text in vi, 111

editoremacs, 110options in vi, 119third-party, 110

EDITOR environment variable,90, 95

electronic mail, 125addresses, 135aliases, 136current message, 130deleting messages, 144forwarding, 141mailing files, 146reading, 130replying to, 139saving to a file, 143sending to users on other

systems, 134sending to users on your

system, 132elm mailer, 125

aliases, 136

command summary, 151commands, 129creating aliases, 137deleting aliases, 138deleting messages, 144exiting, 145forwarding messages, 141getting help, 126listing aliases, 138main screen, 127options, 148packaging files, 146reading mail, 130replying to messages, 139saving messages, 143sending mail, 132, 134starting, 126user level, 150

elmrc file, 148emacs editor, 110enabling a printer, 208entering

commands, 72commands with Key Shell, 215text in vi, 111, 112

ENV variable, 97environment variables, 99

assigning values, 99definition, 95DISPLAY, 95EDITOR, 95HOME, 95, 102HP-UX, 99, 209LOGNAME, 95MAIL, 95PATH, 95, 101PS1, 99SHELL, 88, 95, 100TERM, 95, 104TZ, 95

environment, shell, 86, 94, 97,99

errors

Page 230: Using HP-UX

230 Index

Index

printing, 209escape character in vi, 116example

command line editing, 91commands with arguments, 73commands with options, 72copying a directory to a remote

system, 167copying a file from a remote

system, 166, 173copying a file to a remote

system, 165copying a remote directory to

your system, 168elm mailer options, 149getting a file from a remote

system, 160putting a file onto a remote

system, 162sending mail, 135using local system from remote

system, 171execute permission

for files, 183execute/search permission

for directories, 183exit command, 26, 89exiting

elm, 145ftp, 162vi editor, 118

Ffile

backups, 208changing access to with chmod,

189changing group, 188changing owner with chown,

188compressing, 203concepts, 33

copying with cp command, 42creating with cat command, 34finding by contents with grep,

65finding by name, 67inserting in vi, 123invisible file names, 37listing, 35mailing, 146managing, 33names, 36opening in vi, 110organizing in directories, 45ownership, 188permissions, 183, 189printing, 40protecting with chmod, 189removing with rm command,

42renaming with mv command,

41restoring, 208security, 183transferring from remote

system, 159transferring to remote system,

161transferring with ftp, 156transferring with rcp, 163uncompressing, 203viewing contents of, 38wildcard characters (? and *) in

file names, 63file system

hierarchical, 45, 48filter programs, 85find command, 67finding

file by contents with grep, 65file by name, 67text patterns in vi, 115

forward scrolling in vi, 114forward searching in vi, 115

forwarding message, elm mailer,141

ftpanonymous, 156command summary, 174creating directories, 158exiting, 162get command, 159listing directories, 158put command, 161starting, 157transferring files from remote

system, 159transferring files to remote

system, 161ftp command, 156

GGID, modifying, 209global networks, 155graphical user interface

VUE, 20grep command, 65group

changing, 188modifying membership, 209

group membership of users, 209guidelines

file names, 36password, 28

Hhead command, 39help

elm mailer, 126Key Shell, 215man pages, 30

hierarchical file system, 45, 48hierarchy

file system, 45home directory, 48

Page 231: Using HP-UX

Index

Index 231

HOME environment variable,95, 102

host name, 134setting, 27

HP CDEinformation sources, 20

HP CDE User's Guide, 29HP VUE, 20

command line in, 25manuals, 29

HP-UXcommand line, 25common commands, 203manuals, 29quick reference, 203security patches, 200System Administration Tasks,

29HP-UX directory hierarchy, 48HP-UX Reference manual pages,

30

Iincluding

file in vi, 123information about your system,

29inserting

file in vi, 123installing

guide for, 29Installing HP-UX 10.0, 29peripherals, 29

invisible file names, 37IP address

setting, 27

KKey Shell, 215

correcting errors in commands,90

entering commands, 215

line editing, 90using display, 215

kill command, 75

LLAN, 153leaving

elm, 145ftp, 162vi editor, 118

level of user, elm mailer, 150line editing

choosing a command set, 90commands, 90Key Shell, 90POSIX Shell, 90setting vi, 90

listingfile permissions with ll

command, 184files with ls command, 35

ll command, 184, 185ll -d command, 186local area networks, 153local login script, 97locating

file by contents with grep, 65files using find, 67text patterns with grep, 65

locationin directory hierarchy, 49

logging inas superuser, 24at the command line, 23remote system, 169, 170

logging outat the command line, 26

login program, 94login script, 97

modifying, 97, 209login shell, 89

LOGNAME environmentvariable, 95

looking at a file's contents withmore command, 38

lp command, 40lpstat command

getting printer information, 40ls -a command, 37ls command, 35lsf command, 54

Mmail, 125

addresses, 135aliases, 136command summary, 151current message, 130deleting messages, 144forwarding, 141mailing files, 146reading, 130replying to, 139saving to a file, 143sending to users on other

systems, 134sending to users on your

system, 132mail aliases, 136

creating, 137deleting, 138listing, 138

MAIL environment variable, 95mailing files, 146making

directory with mkdircommand, 54

document in vi, 111file with cat command, 34

man command, 30man pages, displaying, 30managing

files, 33

Page 232: Using HP-UX

232 Index

Index

manuals available, 29ordering, 29

messagesforwarding, 141reading, 130replying to, 139saving to a file, 143sending, 132sending to users on other

systems, 134misspelled words

correcting with spell command,204

mkdir command, 54modifying

system parameters, 27more command, 38Mosaic, 200multiple

commands, 73mv command, 41, 58mv -i command, 41

Nname

finding file by, 67naming files, 36national networks, 155network

computing, 153copying files with ftp, 156global, 155local area, 153national, 155parameters, 27returning to your local system,

171updating from network server,

208wide area, 153

Network File System, 154, 208NFS, 154, 208

node name, 134

Oobsolescence of Bourne Shell, 86online help

elm mailer, 126Key Shell, 215man pages, 30

openingdocument in vi, 110file in vi, 110

operating systemcommands, 25

optionscommand, 72elm mailer, 148vi editor, 119

organizing files in directories, 45owner of file

changing with chown, 188Owner's Guide, 29

Ppackaging files for mailing, 146.. (parent directory), 45password

changing, 28guidelines, 28protecting, 180root, 23rules for choosing a new, 180security, 180superuser, 23

patches, security, 200PATH environment variable, 95,

101path for commands, 101path names, 50performance, system, 207peripherals

adding to system, 209installing, 29

removing from system, 209permissions, 183

access to sensitive files, 187directories, 183, 191displaying directory access,

186displaying file access, 185files, 183, 189listing access permissions with

ll command, 184setting default permissions

with umask, 192PID (process identifier), 74pipeline

command input and output, 83filter programs, 85

POSIX Shell, 25, 94, 97command history, 92correcting errors in commands,

90features, 86line editing, 90re-executing commands, 92

print requestcanceling with cancel

command, 40status with lpstat command,

40printer

adding to system, 208default, 209disabling, 208enabling, 208getting information on, 208removing from system, 208status with lpstat command,

40printing

canceling print request withcancel command, 40

errors, 209with lp command, 40

privileged groups, 195

Page 233: Using HP-UX

Index

Index 233

problemsSystem Administration Tasks,

29process

definition, 74killing, 75

process identifier (PID), 74.profile file, 97program, 74properties, changing

directory with chmod, 191file with chmod, 189

protectingdirectories with chmod, 191directories with umask, 192files and directories, 183files with chmod, 189files with umask, 192your password, 180

PS1 environment variable andshell variable, 99

pwd command, 48

Qquitting

elm, 145ftp, 162vi editor, 118

quoting arguments, 73

Rrcp

command summary, 174copying directories from a

remote system, 168copying directories to a remote

system, 167copying file from remote

system, 166copying file to remote system,

165rcp command, 163

read permissionfor directories, 183for files, 183

reading mail, 130rebooting a system, 207recalling previous commands, 92recovering disk space, 207redirecting

appending output, 44standard input, 79, 81standard input, output, error,

76standard output, 77, 81

re-executing commandsPOSIX Shell, 92

referencing HP-UX variables,99, 209

relative path name, 52remote

commands, running, 172computing, 153file system, 154login, 169

remote systemcopying files, 163copying files from, 159copying files to, 161creating directories, 158listing directories, 158logging in, 169running commands, 173transferring files with ftp, 156transferring files with rcp, 163

remotely copying a directory,163, 167, 168

remotely copying a file, 159, 161,163

removingdirectory with rmdir command,

61file with rm command, 42peripherals, 209printers, 208

user accounts, 209remsh, 172

command summary, 174renaming

file with mv command, 41replace command in vi, 117replacing

text in vi, 117replying to messages, elm

mailer, 139restoring

files, 208restricted shells, 87rlogin, 169

command summary, 174logging in, 170returning to your local system,

171rm command, 42, 62rm -rf command, 62rmdir command, 61root

password, 23user, 23

root directory (/), 47, 48rules

password, 28run level, changing, 207running

commands, 25commands at specified times,

207remote commands, 172, 173

SSAM, 21, 207saving

document in vi, 118mail to a file, 143

scripts.profile, 97login, 98

Page 234: Using HP-UX

234 Index

Index

scrollingdocuments in vi, 114

search path for commands, 101search permission, 183searching

files using find, 67special characters in vi, 116text patterns in vi, 115text patterns with grep, 65

securing your terminal, 179security

auditing, 179default permissions, 192directories, 183, 191files, 183, 189keeping your terminal secure,

179of current directory, 102password, 180sensitive files, 187software patches, 200system, 178

security policy, 22sending mail, 132, 134sensitive files, security for, 187set command in vi, 119set_parms program, 27setting

editor options in vi, 119host name, 27HP-UX variables, 99, 209IP address, 27login environment, 94password, 28search path for commands, 101selected permissions (ACLs),

183system environment, 97terminal characteristics, 105time zone, 27variables, 99vi editor defaults, 121

setting line editor, 90

shar command, 146SHELL environment variable,

88, 95, 100shells, 25

changing your shell, 89default prompts, 87default shell, 94differences, 86environment, 86, 94, 97, 99features compared, 87file names, 87variables, 99variables, PS1, 99

Shells User's Guide, 86showmode option in vi, 119single-quoting arguments, 73software security patches, 200sort command, 82special characters

searching for in vi, 116spelling

checking at command line, 204standard error (stderr), 76standard input (stdin), 76, 79,

81, 83standard output (stdout), 76, 77,

81, 83starting

elm mailer, 126ftp, 157vi editor, 110

startupset_parms program, 27

statusprint requests with lpstat

command, 40printer, using lpstat, 204

stoppingelm, 145print request with cancel

command, 40subdirectory, 45subshell, 99

substitute command in vi, 117substituting

text in vi, 117superuser, 23

logging in, 24password, 23

syntaxcommands, 30, 72mail addresses, 135

systemaliases, elm mailer, 136backups, 208information about, 29login script, 97performance, 207

System AdministrationManager, 21

System Administration Tasks,29

system administration tasks,207

system administrator, 21what to do if none available, 21

system parametersmodifying, 27

system run level, changing, 207system security, 178

Ttail command, 39tasks

advanced, 207changing your password, 28editing in vi, 111finding system information, 29fixing errors in vi, 111logging in at the command line,

23logging in on a remote system,

169logging out at the command

line, 26

Page 235: Using HP-UX

Index

Index 235

printing, 40reading electronic mail, 130replying to electronic mail, 139running commands remotely,

172saving electronic mail, 143sending electronic mail, 132,

134system administration, 207transferring files remotely,

156, 163using electronic mail, 126

tee command, 84TERM = (hp) prompt, 104TERM environment variable,

95, 104terminal

characteristics, 105terminfo database, 104text editors

alternatives to vi, 110text mode in vi, 111text patterns

finding in vi, 115time zone

setting, 27transferring

files with ftp, 156files with rcp, 163

troubleshootingSystem Administration Tasks,

29trusted system, 22, 177trusted system access, 196trusted system password, 181tset command, 105typing

in vi, 112TZ environment variable, 95

Uumask command, 192

uncompressing files, 203updating

from network server, 208Installing HP-UX 10.0, 29

urgent message, sending withelm, 133

userdeactivating, 209

user accountremoving, 209

user aliases, elm mailer, 136user information, modifying, 209user level, elm mailer, 150user name, 89user's guides available, 29

Vvariables

assigning, 99setting and referencing, 99,

209vi editor

.exrc file, 121command mode, 111cursor movement, 113deleting text, 112entering commands, 111entering text, 111, 112environment, 121errors, recovering from, 111inserting file, 123quitting, 118replace command, 117replacing text, 117saving documents, 118starting, 110substitute command, 117substituting text, 117summary of essential

commands, 123text entry mode, 111

viewing

file with the more command,38

first lines of a file, 39last lines of a file, 39

VUE (Visual UserEnvironment), 20

WWAN, 153wc command, 79who command, 77wide area networks, 153wildcard characters (? and *), 63windows

Visual User Environment, 20workstation

rebooting, 207World-Wide Web, 200wrapmargin option in vi, 119write permission

for directories, 183for files, 183

writingstandard input, 79, 81standard output, 77, 81

WWW, 200

Page 236: Using HP-UX

236 Index

Index