Solaris Users Guide

Embed Size (px)

Citation preview

  • 8/10/2019 Solaris Users Guide

    1/166

    Solaris Advanced Users Guide

    Sun Microsystems, Inc.4150 Network CircleSanta Clara, CA 95054U.S.A.

    Part No: 806761210May 2002

  • 8/10/2019 Solaris Users Guide

    2/166

    Copyright 2002 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA95054 U.S.A. All rights reserved.

    This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. Nopart of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any.Third-party software, including font technology, is copyrighted and licensed from S un suppliers.

    Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S.and other countries, exclusively licensed through X/Open Company, Ltd.

    Sun, Sun Microsystems, the Sun logo, docs.sun.com, AnswerBook, AnswerBook2, SunOS, and Solaris are trademarks, registered trademarks, orservice marks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks orregistered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon anarchitecture developed by Sun Microsystems, Inc.

    The OPEN LOOK and Sun Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges thepioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry. Sun holds anon-exclusive license from Xerox to the Xerox Graphical User Interface, which license also covers Suns licensees who implement OPEN LOOK GUIsand otherwise comply with Suns written license agreements.

    Federal Acquisitions: Commercial SoftwareGovernment Users Subject to Standard License Terms and Conditions.

    DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, AREDISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.

    Copyright 2002 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA95054 U.S.A. Tous droits rservs

    Ce produit ou document est protg par un copyright et distribu avec des licences qui en restreignent lutilisation, la copie, la distribution, et ladcompilation. Aucune partie de ce produit ou document ne peut tre reproduite sous aucune forme, par quelque moyen que ce soit, sanslautorisation pralable et crite de Sun et de ses bailleurs de licence, sil y en a. Le logiciel dtenu par des tiers, et qui comprend la technologie relativeaux polices de caractres, est protg par un copyright et licenci par des fournisseurs de Sun.

    Des parties de ce produit pourront tre drives du systme Berkeley BSD licencis par lUniversit de Californie. UNIX est une marque dpose auxEtats-Unis et dans dautres pays et licencie exclusivement par X/Open Company, Ltd.

    Sun, Sun Microsystems, le logo Sun, docs.sun.com, AnswerBook, AnswerBook2, SunOS, et Solaris sont des marques de fabrique ou des marquesdposes, ou marques de service, de Sun Microsystems, Inc. aux Etats-Unis et dans dautres pays. Toutes les marques SPARC sont utilises souslicence et sont des marques de fabrique ou des marques dposes de SPARC International, Inc. aux Etats-Unis et dans dautres pays. Les produitsportant les marques SPARC sont bass sur une architecture dveloppe par Sun Microsystems, Inc.

    Linterface dutilisation graphique OPEN LOOK et Sun a t dveloppe par Sun Microsystems, Inc. pour ses utilisateurs et licencis. Sun reconnatles efforts de pionniers de Xerox pour la recherche et le dveloppement du concept des interfaces dutilisation visuelle ou graphique pour lindustriede linformatique. Sun dtient une licence non exclusive de Xerox sur linterface dutilisation graphique Xerox, cette licence couvrant galement leslicencis de Sun qui mettent en place linterface dutilisation graphique OPEN LOOK et qui en outre se conforment aux licences crites de Sun.

    CETTE PUBLICATION EST FOURNIE EN LETAT ET AUCUNE GARANTIE, EXPRESSE OU IMPLICITE, NEST ACCORDEE, Y COMPRIS DESGARANTIES CONCERNANT LA VALEUR MARCHANDE, LAPTITUDE DE LA PUBLICATION A REPONDRE A UNE UTILISATIONPARTICULIERE, OU LE FAIT QUELLE NE SOIT PAS CONTREFAISANTE DE PRODUIT DE TIERS. CE DENI DE GARANTIE NESAPPLIQUERAIT PAS, DANS LA MESURE OU IL SERAIT TENU JURIDIQUEMENT NUL ET NON AVENU.

    020115@3062

  • 8/10/2019 Solaris Users Guide

    3/166

    Contents

    Preface 9

    1 Differences Between Command Line Interface and Graphical User Interface 13

    Command Line Interface 13

    Graphical User Interfaces 13

    Common Desktop Environment 14

    GNOME Desktop 14

    2 Logging In and Using Basic SunOS Commands 15

    Logging In 15

    Your Login Shell 16

    Logging Out 17

    Keyboard Equivalents 17

    Command Prompt 18

    Typing Commands 19

    Correcting Typing Mistakes 19

    Typing Multiple Commands and Long Commands 19

    Repeating Previous Commands 20

    Adding Command Options 22

    Redirecting and Piping Command Output 22

    Running Commands in the Background 23

    Using a Password 24

    Changing Your Password 25

    Password Aging 25

    Getting Help With OS Commands 26

    3

  • 8/10/2019 Solaris Users Guide

    4/166

    Displaying Manual Pages Withman 26

    Displaying a One-line Summary Withwhatis 26

    Keyword Lookup Withapropos 27

    3 Working With Files and Directories 29

    File Concepts 29

    Using File Commands 30

    Before You Begin 30

    Creating a Test File 30

    Listing Files (ls) 31

    Copying Files (cp) 31

    Moving and Renaming Files (mv) 31

    Deleting Files (rm) 32Displaying File Contents (more,cat) 32

    Displaying File Type (file) 32

    Directories and Hierarchy 33

    Directory Hierarchy 33

    Printing the Working Directory (pwd) 34

    Your Home Directory 34

    Changing the Working Directory (cd) 34

    Creating a Directory (mkdir) 35

    Relative Path Names 36

    Moving and Renaming Directories 36

    Copying Directories 37

    Removing Directories (rmdir) 37

    Viewing Differences Between Files (diff) 37

    Comparing Three Different Files (diff3) 39

    Usingbdiffon Large Files 39

    Searching for Files (find) 39

    File and Directory Security 41

    Displaying Permissions and Status (ls -l) 42

    Listing Hidden Files (ls -a) 43

    Changing Permissions (chmod) 43

    Setting Absolute Permissions 45

    4 Searching Files 49

    Searching for Patterns Withgrep 49

    4 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    5/166

    grepas a Filter 50

    grepWith Multiword Strings 51

    Searching for Lines Without a Certain String 51Using Regular Expressions Withgrep 51

    Searching for Metacharacters 52

    Single or Double Quotes on Command Lines 53

    5 Managing Processes and Disk Usage 55

    Processes and PIDs 55

    What Commands Are Running Now (ps) 55

    Terminating Processes (pkill) 56

    Managing Disk Storage 57

    Displaying Disk Usage (df -k) 57Displaying Directory Usage (du) 57

    6 Using theviEditor 59

    Startingvi 59

    Creating a File 60

    Status Line 60

    Two Modes ofvi 61

    Entry Mode 61

    Command Mode 62

    Ending a Session 62Saving Changes and Quittingvi 63

    Printing a File 64

    BasicviCommands 64

    Moving Around in a File 64

    Inserting Text 67

    Changing Text 68

    Undoing Changes 68

    Deleting Text 69

    Copying and Moving TextYank, Delete, and Put 69

    Using a Count to Repeat Commands 70

    UsingexCommands 71

    Turning Line Numbers On and Off 71

    Copying Lines 72

    Moving Lines 72

    Contents 5

  • 8/10/2019 Solaris Users Guide

    6/166

    Deleting Lines 73

    Searching and Replacing Withvi 73

    Finding a Character String 73Refining the Search 74

    Replacing a Character String 75

    Going to a Specific Line 75

    Inserting One File Into Another 76

    Editing Multiple Files 76

    Summary of Basicvi Commands 76

    7 Using Mail 83

    mailxBasics 83

    Startingmailx 84Sending Yourself a Sample Message 84

    Reading Your Sample Message 85

    Quittingmailx 86

    Reading Messages 86

    Deleting (and Undeleting) Messages 87

    Printing Messages 88

    Sending Messages 89

    Undeliverable Messages 90

    Canceling an Unsent Message 90

    Adding Carbon and Blind Carbon Copies 90

    Inserting a Copy of a Message or File 91Replying to a Message 92

    Saving and Retrieving Messages 93

    Saving and Copying Messages in Files 93

    Saving and Copying Messages in Folders 93

    Reading Messages in Files and Folders 95

    Usingvi Withmailx 96

    Mail Aliases 96

    Setting Up Mail Aliases in.mailrc 97

    Setting Up Mail Aliases in/etc/aliases 98

    Tilde Commands 100

    Getting Help: OthermailxCommands 102

    6 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    7/166

    8 Using Printers 103

    Submitting Print Requests 103

    Submitting Print Requests to the Default Printer 103Submitting Print Requests Using a Printer Name 104

    Requesting Notification When Printing Is Complete 105

    Printing Multiple Copies 105

    Summary Table oflpOptions 105

    Determining Printer Status 106

    Checking on the Status of Your Print Requests 106

    Checking Available Printers 107

    Displaying All Status Information 107

    Displaying Status for Printers 108

    Summary Table oflpstatOptions 108

    Canceling a Print Request 109

    Canceling a Print Request by ID Number 109

    Canceling a Print Request by Printer Name 110

    9 Using the Network 111

    Networking Concepts 111

    Logging In Remotely (rlogin) 112

    rloginWithout a Home Directory 112

    rloginas Someone Else 113

    rloginto an Unknown Machine 113

    Aborting anrloginConnection 114

    Suspending anrloginConnection 114

    Verifying Your Location (who am i) 115

    Copying Files Remotely (rcp) 115

    Copying Files From a Remote Machine 115

    Copying Files From Your Machine to Another 116

    Executing Commands Remotely (rsh) 116

    Viewing User Information (rusers) 117

    Running Networked Applications 118

    Usingrloginto Run a Networked Application 118

    More About Security 119

    10 Customizing Your Working Environment 127

    Modifying Initialization Files 127

    Contents 7

  • 8/10/2019 Solaris Users Guide

    8/166

    Setting Environment Variables 128

    User Profile 129

    Setting thePATHVariable 130Command Aliases 131

    Changing Your Command Prompt 132

    Other Useful Variables 133

    Setting Default File Permissions 134

    A Modifying the Keyboard 137

    Disabling and Enabling the Compose Key 137

    SPARC: Left-Handed Key Remapping 138

    SPARC: Using the Remapping Script 138

    SPARC: Undoing the Keyboard Remapping 140IA: Function Key and Control Key Remapping 141

    IA: Using the Remapping Script 141

    IA: Undoing the Keyboard Remapping 142

    Index 147

    8 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    9/166

    Preface

    This book describes how to use the command line interface (CLI) of the Solaris

    operating environment to perform various system tasks.

    Note The Solaris operating environment runs on two platforms, SPARCand IA.The information in this document pertains to both platforms unless otherwisespecified in a special chapter, section, note, bulleted item,figure, table, or example.

    Who Should Read This BookThis book is for users of the Solaris 9 operating environment who want learn how touse the command line interface.

    Before You Read This BookYour system should be installed and ready for use. If the Solaris operatingenvironment is not installed on your system, see the installation manual specific toyour system before you read this book.

    9

  • 8/10/2019 Solaris Users Guide

    10/166

    How This Book Is OrganizedTheSolaris Advanced Users Guidedescribes the following topics.

    Chapter 1 briefly describes the command line interface and the two graphical userinterfaces supported by the Solaris operating environment, the Common DesktopEnvironment and GNOME.

    Chapter 2 describes how to log in and out of your system and how to use basiccommands to perform system tasks.

    To view license terms, attribution, and copyright statements for bash,tcsh, andzsh, the default path is /usr/share/src. If the Solaris operating environmenthas been installed anywhere other than the default, modify the given path to accessthefile at the installed location.

    Chapter 3 describes how to create, copy, move, and deletefiles and directories. Thischapter also describes how to search forfiles, compare differences betweenfiles,and how to set permissions onfiles and directories.

    Chapter 4 describes how to use thegrepcommand to search through files forspecific character strings.

    Chapter 5 describes how to monitor and manage your systems processes and diskusage.

    Chapter 6 describes how to use thevi text editor to create, edit, save, and printtextfiles.

    Chapter 7 describes how to use themailxtool to read, create, send, and printemail.

    Chapter 8 describes how to printfiles and manage printer status.

    Chapter 9 describes how to perform system tasks from a remote machine.

    Chapter 10 describes how to customize your working environment by modifyingyour system initializationfiles and environment variables.

    Appendix A describes how to customize the key mapping on your keyboard.

    Related BooksThe Solaris operating environment documentation set provides access to a number ofbooks about the Solaris software. These books are organized into the following relatedsets:

    Solaris 9 System Administrator Collection

    10 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    11/166

    This set offers detailed installation and system administration information for avariety of system configurations, including larger networks of Sun workstations.

    Solaris 9 Software Developer CollectionThis set gives software developers the information they need to write, debug, andmaintain programs on the system.

    Solaris 9 Reference Manual Collection

    This set contains a description of every SunOS command. This collection, oftenreferred to as man pages, can optionally be installed as online documentation.

    Solaris 9 User Collection

    This set offers a detailed description of various aspects of the Solaris operatingenvironment. These aspects include:

    How to use SunOScommands How to work with window environments

    How to customize your work environment How to write shell scripts How to use email How to work on the network

    Accessing Sun Documentation OnlineThe docs.sun.comSM Web site enables you to access Sun technical documentationonline. You can browse the docs.sun.com archive or search for a specific book title or

    subject. The URL is http://docs.sun.com.

    Typographic ConventionsThe following table describes the typographic changes used in this book.

    Preface 11

  • 8/10/2019 Solaris Users Guide

    12/166

    TABLE P1Typographic Conventions

    Typeface or Symbol Meaning Example

    AaBbCc123 The names of commands,files, anddirectories; on-screen computer output

    Edit your.loginfile.

    Use ls -a to list all files.

    machine_name% you havemail.

    AaBbCc123 What you type, contrasted withon-screen computer output

    machine_name%su

    Password:

    AaBbCc123 Command-line placeholder: replace witha real name or value

    To delete afile, typermfilename.

    AaBbCc123 Book titles, new words, or terms, orwords to be emphasized.

    Read Chapter 6 in Users Guide.

    These are calledclassoptions.You must berootto do this.

    Shell Prompts in Command ExamplesThe following table shows the default system prompt and superuser prompt for the Cshell, Bourne shell, and Korn shell.

    TABLE P2Shell Prompts

    Shell Prompt

    C shell prompt machine_name%

    C shell superuser prompt machine_name#

    Bourne shell and Korn shell prompt $

    Bourne shell and Korn shell superuser prompt #

    12 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    13/166

    CHAPTER 1

    Differences Between Command LineInterface and Graphical User Interface

    Desktop software should already be installed on your hard disk or on an accessible

    server in your network. If you are unsure that you have access to the desktopsoftware, see your system administrator, or refer to the installation manual for yourspecific platform.

    This chapter briefly describes the differences between the command line interface andthe desktop environment.

    Command Line InterfaceA command line interface (CLI) enables users to type commands in a terminal orconsole window to interact with an operating system. Users respond to a visualprompt by typing a command on a specified line, and receive a response back fromthe system. Users type a command or series of commands for each task they want toperform.

    This book describes how to use the command line interface to perform various systemtasks.

    Graphical User InterfacesA graphical user interface (GUI) uses graphics, along with a keyboard and a mouse, toprovide an easy-to-use interface to a program. A GUI provides windows, pull-downmenus, buttons, scrollbars, iconic images, wizards, other icons, and the mouse toenable users to interact with the operating system or application.

    13

  • 8/10/2019 Solaris Users Guide

    14/166

    The Solaris 9 operating environment supports two GUIs, the Common DesktopEnvironment (CDE) and the GNOME desktop.

    Common Desktop EnvironmentThe Common Desktop Environment (CDE) provides windows, workspaces, controls,menus, and the Front Panel to help you organize and manage your work. You can usethe CDE GUI to organize yourfiles and directories, read, compose and send email,accessfiles, and manage your system.

    For more information, seeSolaris Common Desktop Environment: Users Guide.

    GNOME DesktopGNOME (GNU Network Object Model Environment) is a GUI and set of computerdesktop applications. You can use the GNOME desktop, panel, applications, and toolset to customize your working environment and manage your system tasks. GNOMEalso provides an application set, including a word processor, a spreadsheet program, adatabase manager, a presentation tool, a Web browser, and an email program.

    14 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    15/166

  • 8/10/2019 Solaris Users Guide

    16/166

    hostname console login: spanky

    and press Return. Next, the system requests your password as follows:

    hostname console login: spanky

    Password:

    Type your password at the prompt and press Return. If your account does not have apassword assigned to it, the system logs you in without asking you for a password.Note that the system does not display (echo) your password on the screen as you typeit. The failure to display your password helps to prevent others from discovering yourpassword.

    Your Login ShellIn the chapters that follow, you enter SunOS commands. When you issue a commandto the system, you are actually providing information to a command interpretationprogram, called ashell. The shell program then reads the information you haveprovided and causes the proper action to occur within the system.

    The default shell for SunOS system software is the Bourne shell. The Solaris operatingenvironment also supports the following shells.

    GNU Bourne Again shell (bash) C shell (csh) Korn shell (ksh) TC shell (tcsh)

    Z shell (zsh)

    Each of these shells has its own unique differences.

    Note You can get specific information about any SunOS command, including each ofthe available shells, by viewing its man(manual reference) page. For more informationonman pages, seeDisplaying Manual Pages Withmanon page 26.

    When you initially log in to the system (or open a new terminal or window) and yousee your command prompt, it indicates that a shell program has been started for youautomatically. This shell is called your login shell. If your login shell is not the SunOSdefault (the Bourne shell), it is because a different shell has been specified for you by

    your system administrator.

    Some commands or procedures available when using one shell might not be availablewhen using another shell. Unless stated otherwise, all commands and proceduresdescribed in this manual are available in the Bourne shell.

    16 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    17/166

    Logging OutWhen you havefinished your work session and are ready to exit the operating system,log out by typing the following:

    $ exit

    After a moment, the system once again displays the login prompt:

    $ exit

    hostname console login:

    When you see the login prompt, it indicates that you have successfully logged out.The system is now ready for you or another user to log in.

    Note In the SunOS operating system, turning off your workstation or terminal doesnotnecessarily log you out. Unless you log out explicitly, you might remain logged into the system.

    Keyboard EquivalentsYou can often speed up operations by using a sequence of keystrokes, calledkeyboard

    accelerators, that duplicate the operations of the mouse and menus, and of thepreconfigured keyboard keys.

    The following table lists several command operations and the keyboard equivalentsfor both SPARCand IA machines.

    Note The Meta key is the key on SPARC keyboards and is obtained on IAkeyboards by pressing Ctrl-Alt.

    To use a keyboard accelerator, press and hold the first key (Meta or Ctrl-Alt together)and type the second key. For example, to cut selected text, press and hold the Meta

    key and press X on a SPARC system. On an IA system, press and hold Ctrl and Alttogether and press X simultaneously.

    Chapter 2Logging In and Using Basic SunOS Commands 17

  • 8/10/2019 Solaris Users Guide

    18/166

    TABLE 21Keyboard Accelerators

    Operation Keyboard Equivalent Action

    Again Meta - a Repeats the previous operation

    Copy Meta - c Copies the selection to the clipboard

    Cut Meta - x Cuts the selection and puts it on the clipboard

    Find Meta - f Finds the selection to the right of the caret

    Help Help or F1 Displays a help window with context-sensitivehelp for the object at the pointer location

    New Meta - n Loads a newfile

    Open (File) Meta - o Opens afile (for example, if youve highlighted afile icon in File Manager)

    Open (Window) Meta - w Opens an icon or closes a window to an icon

    Paste Meta - v Copies the clipboard selection to the insertionpoint

    Print Meta - p Sends thefile to the printer (for example, if youvehighlighted afile icon in File Manager)

    Props Meta - i Displays the property window for the applicationat the pointer location

    Redo Shift-Meta - p Undoes an Undo

    Save Meta - s Saves the currentfile

    Stop Stop or Esc Stops the current operation

    Undo Meta - u Undoes the previous operation

    Command PromptWhen you log in, the screen or window displays an initial prompt. The appearance ofthis prompt varies depending on the shell you are using and on how your systemadministrator originally set it up. Because the default command prompt for SunOSsystem software is the dollar sign ($), this prompt is used in most of the examples

    presented in this manual.

    If you decide later that you want to change your command prompt, see ChangingYour Command Prompton page 132 for instructions.

    18 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    19/166

    Typing CommandsWhen you see the command prompt, the system is waiting for you to type acommand. Try typing the commanddateat the prompt, as shown in this example(typedateand press the Return key):

    $ dateMon Sep 17 10:12:51 PST 2001

    $

    This command displays the current date and time. When you type the samecommand, but capitalized, you receive the following message.

    $ DateDate: Command not found.

    $

    The Solaris operating environment interprets an uppercase D differently than alowercased, and theDatecommand fails. Most commands in the Solaris operatingenvironment are lowercase.

    Correcting Typing MistakesThe commands you type are not sent to the system until you pressReturn. If youtype a command incorrectly, but do not press Return, you can correct your mistake inthe following ways.

    Press the Delete or Back Space key to move back a space to the error; or

    Type Ctrl-U to erase the entire line and start over. Hold down theControlkeyand pressu.

    Try both of these methods and see how they work. The Delete/Back Space key varieson some systems. Ctrl-U should work on most systems.

    Typing Multiple Commands and Long CommandsYou can type more than one command on a single line. Simply place a semicolon (;)between the commands, as shown here with the datecommand and thelognamecommand:

    $ date; lognameTue Oct 31 15:16:00 MST 2000

    spooky

    Chapter 2Logging In and Using Basic SunOS Commands 19

  • 8/10/2019 Solaris Users Guide

    20/166

    This command entry displays the current date and time (from the datecommand)and the login name of the user currently logged in to the system (from the lognamecommand).

    If you are typing a long command, you can use the backslash character (\) to continuetyping on a second line. For example:

    $ date; \lognameTue Oct 31 15:17:30 MST 2000

    spooky

    Although thedateand lognamecommands are not long commands, theydemonstrate the concept of continuing a set of commands on the next line. Later, whenthe commands you want to use are longer than the width of your screen, you will seehow useful the backslash character can be.

    Note If you use a desktop window, you might not need to use the backslashcharacter to continue typing commands on the next line. When you reach the end of aline, the commands you type wrap to the next line automatically, and the systemexecutes all commands when you press Return.

    Repeating Previous CommandsThe Korn, Bourne Again, C, TC, and Z shells enable your system to keep a historyofcommands you type and are able to repeat previous commands.

    Note The Bourne shell (sh) does not support thehistorycommand.

    Repeating Commands in the Bourne Again, C, TC, or ZShell

    If you use the Bourne Again, C, TC, or Z shell, type!!and press Return to repeat thelast command you typed.

    example%!!dateTue Oct 31 15:18:38 MST 2000

    example%

    You can also repeat any previously typed command by typing!x, wherex is thedesired commands corresponding number on thehistory list. To see the history list,type thehistorycommand and press Return. The following is an example of whatyou might see.

    20 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    21/166

    example% history1 pwd2 clear

    3 ls -l4 cd $HOME5 logname6 date

    7 history

    Note The Z shell does not display thehistorycommand in the history list.

    Another method for repeating characters from the history list is to follow the! with anegative number. For example, to repeat the second from the last command on thehistory list, type the following command.

    example% !-2dateTue Oct 31 15:20:41 MST 2000

    example%

    Note If you use this command repetition method immediately after the historycommand in the Z shell, increase the negative number after the !by one (!-3).

    Using the previous example history list, thedatecommand is repeated.

    You can also type the !character, followed by the first few characters of a previouscommand to repeat that command. For example, if you had previously typed the

    clearcommand to clear your screen, you could type!clto clear your screen again.With this method for repeating commands, however, you must use enough charactersfor the desired command to be unique in the history list. If you use only one letterafter the!, the system repeats the most recent command that begins with that letter.

    Repeating Commands in the Korn Shell

    If you use the Korn shell, type the following command to repeat the previouscommand.

    $ f c - s -dateTue Oct 31 15:18:38 MST 2000

    $

    You can also repeat any previously typed command by typingfc -sx, wherex is thedesired commands corresponding number on the history list. To see the history list,type thefc -lcommand and press Return. The following example is a samplehistory list.

    Chapter 2Logging In and Using Basic SunOS Commands 21

  • 8/10/2019 Solaris Users Guide

    22/166

    $ fc -l344 pwd345 clear

    346 ls -l347 cd $HOME348 logname349 date350 history

    $

    You can also repeat commands from the history list by following the fc -scommandwith a negative number. For example, to repeat the second from the last command onthe history list, type the following command.

    $ fc -s -2dateTue Oct 31 15:20:41 MST 2000

    $

    Using the previous example history list, the datecommand repeats.

    You can also use the fc -scommand with thefirst few characters of a previouscommand. For example, if you had previously typed the datecommand to displaythe current date, you could typefc -s da to display the date again. However, youmust use enough characters for the desired command to be unique in the history list.If you use only one letter after the fc -scommand, the system repeats the mostrecent command that begins with that letter.

    Adding Command OptionsMany commands haveoptionsthat invoke special features of the command. For

    example, thedatecommand has the option -u, which expresses the date inGreenwich Mean Time instead of local time:

    $ date -uTue Oct 31 22:33:16 GMT 2000

    $

    Most options are expressed as a single character preceded by a dash (-). Not allcommands have options. Some commands have more than one option. If you usemore than one option for a command, you can either type the options separately (-a-b) or together (-ab).

    Redirecting and Piping Command OutputUnless you indicate otherwise, commands normally display their results on the screen.Some special symbols allow you to redirectthe output of a command. For example,you might want to save the output to afile rather than display it on the screen. Thefollowing example illustrates the use of the redirect symbol (>).

    22 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    23/166

    $ date > sample.file

    $

    In this example, the output from thedatecommand is redirected to a new file calledsample.file. You can display the contents ofsample.fileby typing themorecommand.

    $ more sample.fileTue Oct 31 15:34:45 MST 2000

    $

    As you can see, the contents ofsample.filenow contain the output from the datecommand. See Chapter 3 for information on themorecommand.

    Sometimes you might want to redirect the output of one command as input to anothercommand. A set of commands strung together in this way is called a pipeline. Thesymbol for this type of redirection is a vertical bar (|) called apipe.

    For example, instead of saving the output of a command to a file, you might want todirect it as input to the command for printing (lp) by using the pipe symbol (|). Tosend the output from the datecommand directly to the printer, type the following:

    $ date | lprequest id is jetprint-46 (1 file)

    $

    This pipeline would print the results of the datecommand. SeeSubmitting PrintRequests to the Default Printeron page 103 for information on using thelpcommand to printfiles.

    The command redirection examples shown here are simple, but when you learn moreadvanced commands, you willfind many uses for piping and redirection.

    Running Commands in the BackgroundWhen you type a command and press the Return key, your system runs the command,waits for the command to complete a task, and then prompts you for anothercommand. However, some commands can take a long time to finish, and you mightprefer to type other commands in the meantime. If you want to run additionalcommands while a previous command runs, you can run a command in thebackground.

    If you know you want to run a command in the background, type an ampersand (&)after the command as shown in the following example.

    $ bigjob &[1] 7493

    $

    Chapter 2Logging In and Using Basic SunOS Commands 23

  • 8/10/2019 Solaris Users Guide

    24/166

    The number that follows is the process id. The command bigjobwill now run in thebackground, and you can continue to type other commands. After the job completes,you will see a message similar to the following the next time you type anothercommand, such asdatein the following example.

    $ dateTue Oct 31 15:44:59 MST 2000[1] Done bigjob

    $

    If you plan to log off before a background job completes, use thenohup(no hangup)command to enable the job to complete, as shown in the following example. If you donot use thenohupcommand , the background job terminates when you log off.

    $ nohup bigjob &[3] 7495

    $

    Using a PasswordTo ensure your systems security, the Solaris operating environment requires you use apassword to access your system. Changing your password several times a year helpsto ensure that you are the only user with easy access to your account.

    Note If you believe someone has used your account without your permission,change your password immediately.

    When you choose a password, follow these guidelines.

    Choose a password that you can remember without writing it down. A passwordthat you cannot remember is worse than one that is too easily guessed.

    Choose a password that is at least six characters long and contains at least onenumber.

    Dont use your own name or initials or the name or initials of your spouse.

    Dont use the names of pets or objects common to your interests.

    Dont use all capital letters.

    If you have more than one account, dont use the same password for every

    account. Avoid using the characters Ctrl-C, Ctrl-Z, Ctrl-U, Ctrl-S, Esc, Tab, #, and @ in your

    password. The terminal might interpret these characters as signals rather than textcharacters, and this interpretation would preclude you from properly typing inyour password.

    24 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    25/166

  • 8/10/2019 Solaris Users Guide

    26/166

    The system then automatically runs thepasswdprogram and prompts you for a newpassword.

    If, for example, theminimumage of your password has been set for two weeks, andyou try to change your password before the minimum life span has elapsed, thefollowing message displays.

    Sorry, less than 2 weeks since the last change.

    For more information onpasswd(1) and password aging, refer to the man Pages(1):User Commands.

    Getting Help With OS CommandsThis section describes various online help features. These features enable you to viewreference information from your workstation or terminal.

    Displaying Manual Pages WithmanIf you know the name of a command, but you are not sure what it does, themancommand can be helpful. Type the following to find out more about this command:

    $ man man

    This command displays the first part of a SunOS manual reference page in thewindow display area. Press the space bar to see the next screen, or press the Q key toquit and return to the command prompt. Use themancommand to see all the availableoptions and to show the proper command syntax. Manual reference pages oftenprovide examples that illustrate various uses of the command.

    Displaying a One-line Summary WithwhatisIf you want just a one-line summary of the commands function, use thewhatiscommand, as shown here:

    $ whatis datedate (1) -display or set the date

    $

    The number in parentheses after the command name in the previous exampleindicates the Reference Manual section to which this command belongs. Commandsare grouped into various categories according to function. Most user commands are in

    26 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    27/166

    section 1. By common convention, the section number is displayed in parentheses afterthe name of the command. You canfind the printed manual reference page for acommand in alphabetical order within its group.

    Note Thewhatiscommand is only available if your system administrator has setup a special database of command descriptions.

    Keyword Lookup WithaproposIf you know what you want to do, but you do not know which command to use, usetheaproposcommand to locate commands by keyword lookup. Theaproposcommand lists all commands that have one-line summaries that contain any keywords

    you supply. The output of theaproposcan be lengthy, as some keywords mightappear in many places.

    Note Theaproposcommand is only available if your system administrator has setup a special database of command descriptions.

    To view examples ofaproposoutput, type one or more of the following commands.

    apropos who apropos execute apropos apropos

    If you do type a keyword that generates an unreasonably lengthy display, press Ctrl-Cto interrupt the display and return you to the command prompt. Hold down theControl key and pressc.

    Chapter 2Logging In and Using Basic SunOS Commands 27

  • 8/10/2019 Solaris Users Guide

    28/166

    28 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    29/166

    CHAPTER 3

    Working With Files and Directories

    You can use the SunOS command line to work with, organize, and manage files and

    directories. You type thefile and directory names with SunOS commands to completespecific operations. The command line operates differently than a desktop FileManager. In a File Manager, you can displayfiles as icons that you can click on andmove, and you can select commands from menus.

    This chapter describes the following topics.

    File Conceptson page 29 Using File Commandson page 30 Directories and Hierarchyon page 33 Viewing Differences Between Files (diff)on page 37 Searching for Files (find)on page 39 File and Directory Securityon page 41

    File ConceptsAfileis the basic unit in the SunOS operating system. Almost everything is treated as afile, including the following items.

    DocumentsThese items include textfiles, such as letters or reports, computersource code, or any other document that you write and want to save.

    Commands Most commands areexecutablefile. That is, they arefiles you canexecute to run a particular program. For example, thedatecommand in theprevious chapter, which executes a program that provides the current date, is an

    executablefile.

    DevicesYour terminal, printer, and disk drive(s) are all treated as files.

    DirectoriesA directory is simply afile that contains otherfiles.

    29

  • 8/10/2019 Solaris Users Guide

    30/166

    The following section explains the commands for creating, listing, copying, moving,and deletingfiles. This section also includes information on how to list the contents ofafile and how to determine the nature of afile.

    Using File CommandsEach of the command descriptions in this section includes an example of how to usethe command. Try the examples as you read the text.

    Before You BeginBefore you experiment with files, make sure that you are in yourhome directory. Yoursystem administrator established this directory for you at your account creation. Toavoid changes to parts of your system that other users expect to remain unchanged,perform the following tasks in your home directory.

    To make certain that you are in your home directory, type thecd(change directory)command. This command moves you to your home (default) directory. Then type thepwd(print working directory) command to display your current location within thefile system. The directory displayed is your home directory:

    $ cd$ pwd

    /export/home/username

    In this example, the users home directory is/export/home/username, whereusernameis the name of the user who owns the home directory.

    Creating a Test FileUse thetouchcommand to create an empty file.

    $ touch tempfile

    $

    If a file by the name you specify does not exist, thetouchcommand creates an emptyfile.

    Note If thefile already exists,touchupdates the lastfile access time.

    30 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    31/166

    Listing Files (ls)

    Now list thefile with thels

    command to verify that youve created it:$ ls tempfile

    tempfile

    When you type thelscommand by itself, it lists all thefiles in your current location.If you type thelscommand with a specificfile name, it lists only thatfile, if thefileexists.

    For more information on listingfiles, see the man pagels(1).

    Copying Files (cp)

    Use thecpcommand to copytempfileto afile calledcopyfile:$ cp tempfile copyfile

    $

    Now list bothfiles. Notice that both names end with the characters file.You can usethewildcardcharacter, asterisk (*), to match any character or sequence of characters.The commandls *filelists bothtempfileandcopyfile, and any otherfile inthis directory with a name that ends withfile.

    $ ls *file

    copyfile tempfile

    Notice thatcopyfileis listedfirst. Files are listed in alphabetical order. Capitalletters and numbers precede lowercase letters.

    For detailed information on copyingfiles, see the man pagecp(1).

    Moving and Renaming Files (mv)You can move and renamefiles by using the same command,mv(move). In thisexample, use themvcommand to renametempfiletoemptyfile:

    $ mv tempfile emptyfile

    $

    Then list bothfiles again to verify the change.

    $ ls *file

    copyfile emptyfile

    tempfileis replaced byemptyfile.

    For more information on moving and renaming files, see the man pagemv(1).

    Chapter 3Working With Files and Directories 31

  • 8/10/2019 Solaris Users Guide

    32/166

    Deleting Files (rm)

    Use therm(remove) command to deletecopyfile, and verify the result with thelscommand:

    $ rm copyfile$ ls *file

    emptyfile

    Caution Be careful when you use thermcommand, and be particularly careful whenyou usermwith the wildcard character (*). You cannot recover files that you haveremoved withrm.

    For more information on therm(1) command, refer to theman Pages(1): UserCommands.

    Displaying File Contents (more,cat)Use themorecommand to display the contents of a file. Typemoreand follow it withthe name of thefile to be displayed. The contents of the file scroll down the screen. Ifthefile is longer than one screen, this message appears:

    --More--(nn%)

    wherennis the percentage of the file already displayed.

    You can also use thecatcommand to display the contents of afile, but it displays the

    file contents rapidly without pausing. Thecat(concatenate) command is more oftenused to join two or morefiles into one largefile, as in this example:

    $ cat file1 file2 file3 > bigfile$ ls *filebigfilefile1file2file3

    $

    For further information on themore(1) orcat(1) commands, refer to theman Pages(1):User Commands.

    Displaying File Type (file)Somefiles, such as binaryfiles and executablefiles, are not printable and cannot bedisplayed on the screen. Use thefilecommand to show thefile type.

    32 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    33/166

    $ file *myscript: executable shell scriptprint.ps: PostScript document

    save.txt: ascii text

    Directories and HierarchyThis section describes the directory hierarchy that the Solaris operating environmentuses to manage and organize files.

    Directory HierarchyFiles are grouped into directories, and directories are organized in a hierarchy. At thetop of the hierarchy is therootdirectory, symbolized by/.

    In the following example, Figure 31, each directory in thefile system contains manysubdirectories. The/character distinguishes directory levels. The directory/(root)contains the subdirectories/usr,/bin,/export/homeand/lib, among otherssubdirectories. The subdirectory/export/homecontainsuser1,user2, anduser3.

    When you initiate commands, you specify directories andfiles by including the namesof the directories that contain thefiles or directories you want to work with. Thenames of directories and the files beneath them, combined with slash separators,constitute apath name. For example, the path name for theuser3directory in the

    following illustration is/export/home/user3.

    root (/)

    export lib usr

    homeccs lib

    user2user1 user3

    bin

    FIGURE 31File System Hierarchy

    All subdirectory names andfile names within a directory must be unique. However,names within different directories can be the same. For example, the directory/usrcontains the subdirectory/usr/lib. No conflict occurs between/usr/liband/libbecause the path names are different.

    Chapter 3Working With Files and Directories 33

  • 8/10/2019 Solaris Users Guide

    34/166

  • 8/10/2019 Solaris Users Guide

    35/166

    example% cd ~/music

    You can also use this shortcut to specify another users home directory. For example:

    example% cd ~username

    whereusernameis another users login name, you would change to that users homedirectory.

    Note The Bourne shell does not support the ~ shortcut.

    If you use the Bourne shell, your system administrator might have configured thesystem so that you can type$hometo specify your home directory. With thisconfiguration, you type the following command to change your working directory tothe subdirectorymusicin your home directory.

    $ cd $home/music

    The directory immediatelyabovea subdirectory is called the parent directory. In thepreceding example,/homeis the parent directory of/home/user1. The symbol..(dot-dot) represents the parent directory. The commandcd ..changes the workingdirectory to the parent directory, as in this example:

    $ pwd/home/user1$ cd ..$ pwd

    /home

    If your current working directory is/home/user1and you want to work with some

    files in/home/user2, type the following command.$ pwd/home/user1$ cd ../user2$ pwd

    /home/user2

    ../user2tells the system to look in the parent directory foruser2. As you can see,this command is much easier than typing the entire path name/home/user2.

    Creating a Directory (mkdir)

    To create a new directory, type themkdircommand and follow it with the name ofthe new directory.

    $ mkdir veggies$ cd veggies$ mkdir broccoli

    Chapter 3Working With Files and Directories 35

  • 8/10/2019 Solaris Users Guide

    36/166

    $ cd broccoli$ pwd

    /home/user2/veggies/broccoli

    Relative Path NamesThe full path name of a directory or a file begins with a slash (/) and describes theentire directory structure between thatfile (or directory) and the root directory.However, you can often use a shorter name that de fines thefile or directoryrelativetothe current working directory.

    When you are in a parent directory, you can move to a subdirectory by using only thedirectory name and not the full path name. In the previous example, the commandcdveggiesuses the relative path name of the directoryveggies. If the current workingdirectory is/home/user2, the full path name of this directory is

    /home/user2/veggies.

    Create several different subdirectories, and then move around within this directorystructure. Use both full path names and relative path names, and confirm yourlocation with thepwdcommand.

    Moving and Renaming DirectoriesYou rename a directory by moving it to a different name. Use themvcommand torename directories.

    $ pwd/home/user2/veggies

    $ lsbroccoli$ mv broccoli carrots$ ls

    carrots

    You can also usemvto move a directory to a location within another directory.

    $ pwd/home/user2/veggies$ lscarrots$ mv carrots ../veggies2$ ls ../veggies2

    carrots

    In this example, the directorycarrotsis moved fromveggiestoveggies2withthemvcommand.

    36 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    37/166

  • 8/10/2019 Solaris Users Guide

    38/166

    When thediffutilityfinds a line or lines that differ,diffdetermines if the differenceis the result of an addition, a deletion, or a change to the line, and how many lines areaffected.difftells you the respective line number or numbers in eachfile, followedby the relevant text from each file.

    If the difference is the result of an addition,diffdisplays a line with the followingformat.

    l[,l] a r[,r]

    In the previous example,l is a line number inleftfileandris a line number inrightfile.

    If the difference is the result of a deletion,diffuses adin place ofa. If the differenceis the result of a change on the line,diffuses ac.

    The relevant text from both files immediately follow the line number information. Text

    fromleftfileis preceded by a left angle bracket ().

    This example shows two sample files, followed by theirdiffoutput.

    $ cat sched.7.15Week of 7/15

    Day: Time: Action Item: Details:

    T 10:00 Hardware mtg. every other weekW 1:30 Software mtg.T 3:00 Docs. mtg.F 1:00 Interview$ cat sched.7.22Week of 7/22

    Day: Time: Action Item: Details:

    M 8:30 Staff mtg. all dayT 10:00 Hardware mtg. every other weekW 1:30 Software mtg.T 3:00 Docs. mtg.$ diff sched.7.15 sched.7.221c1< Week of 7/15---> Week of 7/224a5> M 8:30 Staff mtg. all day8d8

    < F 1:00 Interview

    If the twofiles to be compared are identical,diffdoes not display output.

    For more information on thediff(1) command, refer to theman Pages(1): UserCommands.

    38 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    39/166

    Comparing Three Different Files (diff3)

    To compare three different versions of afile, use thediff3command.$ diff3 file1 file2 file3

    diff3compares three versions of afile and publishes the differing ranges of text thatareflagged with these codes:

    ==== all threefiles differ

    ====1file1is different

    ====2file2is different

    ====3file3is different

    Usingbdiffon Large FilesIf you are comparing large files, usebdiffinstead ofdiff. Use thediffcommandsyntax withbdiff.

    $ bdiff leftfile rightfile

    Usebdiffinstead ofdifffor files longer than 3500 lines.

    Searching for Files (find)Thefindcommand searches forfiles that meet conditions you specify, starting from adirectory you name. For example, you might search for file names that match a certainpattern or that have been modified within a specified time frame.

    Unlike most commands,findoptions are several characters long. You must specifythe starting directory before your desired options.

    $ find directory options

    In the previous example,directoryis the name of the starting directory and optionsrepresents the options for thefindcommand.

    Each option describes a criterion for selecting a file. A file must meet all criteria to beselected. The more options you apply, the narrower the field becomes. The-printoption indicates that you want the system to display the results.

    Chapter 3Working With Files and Directories 39

  • 8/10/2019 Solaris Users Guide

    40/166

    The-namefilenameoption tellsfindto selectfiles that matchfilename. Herefilenameistaken to be the rightmost component of afiles full path name. For example, therightmost component of thefile/usr/bin/calendariscalendar. This portion of afiles name is often called thebase name.

    For example, to see whichfiles within the current directory and its subdirectories endins, type the following command.

    $ find . -name *s -print./programs./programs/graphics./programs/graphics/gks./src/gks

    $

    The following table describes other options of thefindcommand.

    TABLE 31findOptions

    Option Description

    -namefilename Selectsfiles with a rightmost component thatmatchesfilename. Surroundfilenamewithsingle quotes if it includesfilenamesubstitution patterns.

    -useruserid Selectsfiles that are owned by userid.useridcan be either a login name or user ID number.

    -groupgroup Selectsfiles that belong togroup.

    -m -timen Selectsfiles that have been modified withinndays.

    -newercheckfile Selectsfiles that have been modified morerecently thancheckfile.

    You can specify an order of options by combining options within escaped parentheses(for example, \(options\) ). Within escaped parentheses, you can use the-oflagbetween options to indicate thatfindshould selectfiles that qualify under eithercategory, rather than just thosefiles that qualify under both categories.

    $ find . \( -name AAA -o -name BBB \) -print./AAA

    ./BBB

    In the previous example, thefindcommand searches in the.directory for allfiles

    that are namedAAA, then looks for all files namedBBB.findthen displays the resultsof both searches.

    You can invert the sense of an option by including an escaped exclamation pointbefore the option.findthen selectsfiles for which the option does not apply:

    40 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    41/166

    $ find . \!-name BBB -print

    ./AAA

    You can also usefindto apply commands to the files it selects with the followingoptions.

    -execcommand{}\;

    You terminate this option with an escaped semicolon (\;). The quoted braces arereplaced with thefile names thatfindselects.

    You can usefindto automatically remove temporary work files. If you name yourtemporaryfiles consistently, you can usefindto search for and remove these files. Forexample, if you name your temporary filesjunkordummy, this commandfinds andremoves thefiles.

    $ find . \( -name junk -o -name dummy \) -exec rm {} \;

    For more information on searching for files, see the man pagefind(1).

    File and Directory SecurityFile permissions help to protectfiles and directories from unauthorized reading andwriting. Often you will have files you want to allow others to read but not change. Inother situations, you might want to share executablefiles or programs. Filepermissions enable you to control access to yourfiles.

    The following list describes the three basicfile and directory permission types.

    rreadpermission. A file must be readable in order for you to examine or copy it.A directory must be readable in order for you to list its contents.

    w writepermission. A file must be writable in order for you to modify it, removeit, or rename it. A directory must be writable in order for you to add or deletefilesin it.

    x executepermission. A file with executable permissions is one you can run, suchas a program. A directory must be executable in order for you to gain access to anyof its subdirectories.

    You can set permissions for three categories of users.

    User Thefile owner

    GroupOther users within the same group as the user, such as all staff membersof a particular division. The system administrator establishes and maintainsgroups.

    OthersAll users.

    Chapter 3Working With Files and Directories 41

  • 8/10/2019 Solaris Users Guide

    42/166

    Displaying Permissions and Status (ls -l)

    Use the-lwith thelscommand to display a long listing offiles and directories inalphabetical order.

    $ pwd/home/hostname/user2$ ls -ltotal 8drwxr-xr-x 2 user2 users 1024 Feb 9 14:22 directory1-rw-r--r-- 1 user2 users 0 Feb 10 10:20 emptyfile-rw-r--r-- 1 user2 users 104357 Feb 5 08:20 large-filedrwxr-xr-x 3 user2 users 1024 Feb 10 11:13 veggies2

    Permissions Links Owner Group Size Date Time File ordirectory name

    FIGURE 32Displaying Permissions and Status

    Thefirst character on the line indicates thefile type. A dash (-) indicates an ordinaryfile, adindicates a directory, and other characters can indicate other specialfile types.

    The next nine characters indicate the permissions for the file or directory. The ninecharacters consist of three groups of three, showing the permissions for the owner, theowners group, and the world, respectively. The permissions foremptyfilearerw-r--r--, indicating that the owner can read and write this file, everyone can readit, and no one can execute it. The permissions for the directoryveggies2arerwxr-xr-x, indicating that everyone has read and execute permissions, but only theowner can write to it.

    In addition tofile permissions, the display shows the following information:

    Number of links to thisfile or directory

    Name of the owner (user2in this case)

    Name of the group owner (usersin this case)

    Number of bytes (characters) in thefile

    Date and time thefile or directory was last updated

    Name of thefile or directory

    Use thecdcommand to move to your home directory, and try thels -lcommand.

    Now type the following command, where dirnameis the name of an actual

    directory in yourfile system.

    $ ls -l dirname

    42 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    43/166

    When you give the name of a directory, thels -lcommand prints information on allthefiles and directories in that directory.

    Listing Hidden Files (ls -a)Somefiles are not listed by thelscommand. Thesefiles have names that begin withthe character.(calleddot), such as.cshrc,.loginand.profile. Use thels -acommand to list these dotfiles:

    $ ls -a....cshrc.login.profile

    emptyfile

    Notice that thefiles beginning with.are listed before the other files. Thefile.is thereference for the current directory, and thefile..is the reference for the parentdirectory.

    In general, system utilities use files that begin with.and the user cannot modify thesefiles. Some exceptions to this rule do exist.

    Changing Permissions (chmod)Use thechmodcommand to change permissions for a file or directory. You must be theowner of afile or directory, or have root access, to change its permissions. The general

    form of thechmodcommand is:

    chmod permissions name

    In this example,permissionsindicates the permissions to be changed and nameis thename of the affectedfile or directory.

    You can specify the permissions in several ways. Here is one of the forms that is easyto use:

    1. Use one or more letters to indicate the type of users.

    u(for theuser) g(forgroup) o(forothers)

    a(forall three of the previous categories.))2. Indicate whether the permissions are to be added (+) or removed (-).

    3. Use one or more letters to indicate the permissions.

    r(forread)

    Chapter 3Working With Files and Directories 43

  • 8/10/2019 Solaris Users Guide

    44/166

    w(forwrite)

    x(forexecute)

    In the following example, write permission is added to the directorycarrotsforusers who belong to the same group (thus,permissionsisg+wandnameiscarrots).

    $ cd veggies2$ ls -ldrwxr-xr-x 2 user2 users 512 Nov 1 09:11 carrots$ chmod g+w carrots$ ls -ldrwxrwxr-x 2 user2 users 512 Nov 1 09:11 carrots

    $

    Thechmodg+wcarrotscommand in the previous example gives the group writepermission on thefilecarrots. The hyphen (-) in the set of permissions for group ischanged to aw.

    To make this same directory unreadable and unexecutable by other users outside yourgroup type the following commands.

    $ ls -ldrwxrwxr-x 2 user2 users 512 Nov 1 09:11 carrots$ chmod o-rx carrots$ ls -ldrwxrwx--- 2 user2 users 512 Nov 1 09:11 carrots

    $

    Now, ther(for read) and thex(for execute) in the set of permissions for other usersare both changed to hyphens (-).

    When you create a newfile, the system automatically assigns the followingpermissions.

    -rw-r--r--

    When you create a new directory, the system automatically assigns the followingpermissions.

    drwxr-xr-x

    For example, to make a newfileturnipexecutable by its owner (user2), type thefollowing command.

    $ ls -l turnip-rw-r--r-- 1 user2 users 124 Nov 1 09:14 turnip$ chmod u+x turnip$ ls -l turnip

    -rwxr--r-- 1 user2 users 124 Nov 1 09:14 turnip$

    44 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    45/166

    If you want to change permissions for all categories of users, use the-aoption of thelscommand. To make a new filegarlicexecutable by everyone, type the followingcommand.

    $ ls -l garlic-rw-r--r-- 1 user2 users 704 Nov 1 09:16 garlic$ chmod a+x garlic$ ls -l garlic-rwxr-xr-x 1 user2 users 704 Nov 1 09:16 garlic

    $

    Thexin the output of thels -lcommand indicatesgarlicis executable byeveryone.

    You can also use the*wildcard character to change permissions for groups offilesand directories. For example, to change the permissions for all the files in the currentdirectoryveggiesso that thefiles can be written by you alone, type the followingcommand.

    $ pwd/home/user2/veggies$ ls -l-rwxrwxrwx 1 user2 users 5618 Nov 1 09:18 beets-rwxrwxrwx 1 user2 users 1777 Nov 1 09:18 corn-rwxrwxrwx 1 user2 users 3424 Nov 1 09:18 garlic-rwxrwxrwx 1 user2 users 65536 Nov 1 09:18 onions$ chmod go-w *$ ls -ltotal 152-rwxr-xr-x 1 user2 users 5618 Nov 1 09:18 beets-rwxr-xr-x 1 user2 users 1777 Nov 1 09:18 corn-rwxr-xr-x 1 user2 users 3424 Nov 1 09:18 garlic-rwxr-xr-x 1 user2 users 65536 Nov 1 09:18 onions

    $

    Note Perform thischmodoperation on the current directory only.

    Setting Absolute PermissionsIn the previous section, you used thechmodcommand to changefile permissionsrelative to their current settings. You can also set the permissions for a file or directoryabsolutelyby using numeric codes with thechmodcommand.

    The syntax for this usage of thechmodcommand is:

    chmodnumcode name

    In this example,numcodeis the numeric code andnameis the name of thefile ordirectory for which you are changing permissions.

    Chapter 3Working With Files and Directories 45

  • 8/10/2019 Solaris Users Guide

    46/166

    The complete numeric code consists of three numbers. One number is used for each ofthe three categories: user, group, and others. For example, the following command setsabsolute read, write, and execute permissions for the user and the group, and executepermissions only for others.

    $ chmod 771 garlic

    Table 32 illustrates how the the code771describes the permissions forgarlic.

    TABLE 32Permissions for garlic

    Permission User Group Others

    Read 4 4 0

    Write 2 2 0

    Execute 1 1 1

    Total 7 7 1

    Each of the columns in Table 32 represents one of the categories: user, group, andothers. To set read permissions, add 4 to the appropriate column. To set writepermissions, add 2. To add execute permissions, add 1. The total in all three columnsin the last row of the table is the complete numeric code.

    The following is another example of using numeric codes to set absolute permissions,with the inclusion of thels -lcommand to demonstrate the results.

    $ ls -l onions-rwxr-xr-x 1 user2 users 65536 Nov 1 09:18 onions$ chmod 755 onions$ ls -l onions

    -rwxr-xr-x 1 user2 users 65536 Nov 1 09:18 onions$

    Thechmod 755 onions command sets the permissions for the fileonionsso thatthe user can read, write, and execute, group members can read and execute, and otherscan read and execute. Table 33 describes the numeric code that is used to set thepermissions foronions.

    TABLE 33Permissions for onions

    Permission User Group Others

    Read 4 4 4

    Write 2 0 0

    Execute 1 1 1

    Total 7 5 5

    46 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    47/166

    To provide read, write, and execute permissions for the filecabbageto yourself, yourgroup, and all other users, type the following command.

    $ ls -l cabbage-rw-r--r-- 1 user2 users 75 Nov 1 09:28 cabbage$ chmod 777 cabbage$ ls -l cabbage-rwxrwxrwx 1 user2 users 75 Nov 1 09:28 cabbage

    $

    Table 34 describes the numeric code that is used to set permissions in the previousexample.

    TABLE 34Permissions for cabbage

    Permission User Group Others

    Read 4 4 4

    Write 2 2 2

    Execute 1 1 1

    Total 7 7 7

    The numeric code777represents the maximum level of permissions you can provide.

    Similar to changing relative permissions, you can also use the wildcard character*toset absolute permissions for all in the files in the current directory. For example,suppose you want to set absolute permissions for all files in the current directory asfollows:

    Owner Read, write, and execute permissions

    Group Read and write permissions Others Execute permissions

    To set these permissions, type the following commands.

    $ pwd/home/user2/veggies$ ls -l-rwxrwxrwx 1 user2 users 5618 Nov 1 09:18 beets-rwxrwxrwx 1 user2 users 1777 Nov 1 09:18 corn-rwxrwxrwx 1 user2 users 3424 Nov 1 09:18 garlic-rwxrwxrwx 1 user2 users 65536 Nov 1 09:18 onions$ chmod 751 *$ ls -l-rwxr-x--x 1 user2 users 5618 Nov 1 09:18 beets-rwxr-x--x 1 user2 users 1777 Nov 1 09:18 corn-rwxr-x--x 1 user2 users 3424 Nov 1 09:18 garlic-rwxr-x--x 1 user2 users 65536 Nov 1 09:18 onions

    $

    Chapter 3Working With Files and Directories 47

  • 8/10/2019 Solaris Users Guide

    48/166

    Thepwdcommand is included in this example to illustrate that the directory on whichyou perform this operation must be the current directory. Thels -lcommand isshown only to illustrate the changes in permissions. When setting absolutepermissions, you do not need to know what the permissions are currently.

    For more information on thechmod(1) command, refer to theman Pages(1): UserCommands.

    48 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    49/166

    CHAPTER 4

    Searching Files

    This chapter describes how to search directories and files for keywords and strings by

    using thegrepcommand.

    Searching for Patterns WithgrepTo search for a particular character string in afile, use thegrepcommand. The basicsyntax of thegrepcommand is:

    $ grep string file

    In this example,stringis the word or phrase you want tofind, andfileis thefile to be

    searched.

    Note A stringis one or more characters. A single letter is a string, as is a word or asentence. Strings can include blank spaces, punctuation, and invisible (control)characters.

    For example, tofind Edgar Allan Poes telephone extension, typegrep, all or part ofhis name, and thefile containing the information:

    $ grep Poe extensionsEdgar Allan Poe x72836

    $

    Note that more than one line might match the pattern you give.

    $ grep Allan extensionsDavid Allan x76438Edgar Allan Poe x72836

    49

  • 8/10/2019 Solaris Users Guide

    50/166

  • 8/10/2019 Solaris Users Guide

    51/166

  • 8/10/2019 Solaris Users Guide

    52/166

    A dollar-sign ($) metacharacter indicates the end of the line. The followingcommand displays any line in whichbis the last character on the line.

    $ grep b$ list

    The following command displays any line in the filelistwherebis theonlycharacter on the line.

    $ grep ^b$ list

    Within a regular expression, dot (.)finds any single character. The followingcommand matches any three-character string with anas thefirst two characters,includingany, and, management,andplan(because spaces count, too).

    $ grep an. list

    When an asterisk (*) follows a character,grepinterprets the asterisk aszero ormore instances of that character.When the asterisk follows a regular expression,grepinterprets the asterisk aszero or more instances of characters matching the

    pattern.

    Because it includes zero occurrences, the asterisk can create a confusing commandoutput. If you want to find all words with the lettersquin them, type thefollowing command.

    $ grep qu* list

    However, if you want to find all words containing the lettern,type the followingcommand.

    $ grep nn* list

    If you want tofind all words containing the patternnn,type the followingcommand.

    $ grep nnn* list

    To match zero or more occurrences ofanycharacter inlist, type the followingcommand.

    $ grep .* list

    Searching for MetacharactersTo use thegrepcommand to search for metacharacters such as& ! . * ?and\,precede the metacharacter with a backslash (\). The backslash tellsgrepto ignore(escape) the metacharacter.

    For example, the following expression matches lines that start with a period, and isuseful when searching fornroffortroffformatting requests (which begin with aperiod).

    $ grep ^\.

    52 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    53/166

  • 8/10/2019 Solaris Users Guide

    54/166

    $ grep $ list

    However, if you type the following command, the system displays only those lines

    that contain the$character.

    $ grep \$ list

    For more information on thegrep(1) command, refer to theman Pages(1): UserCommands.

    54 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    55/166

    CHAPTER 5

    Managing Processes and Disk Usage

    This chapter describes the following topics..

    Processes and PIDson page 55 Terminating Processes (pkill)on page 56 Managing Disk Storageon page 57

    Processes and PIDsAfter your system interprets each command, the system creates an independent processwith a unique process identification number (PID) to perform the command. Thesystem uses the PID to track the current status of each process.

    What Commands Are Running Now (ps)Use thepscommand to see what processes are currently running.Thepscommandshows theprocess identification number(listed underPID) for each process you own,which is created after you type a command. This command also shows you theterminalfrom which it was started (TTY), thecpu timeit has used so far (TIME), and thecommandit is performing (COMMAND).

    If you add the-loption to thepscommand, the system displays other processinformation, including thestateof each running process (listed underS). The

    following list defines the codes used to describe processes. OProcess is running on a processor

    SSleeping: Process is waiting for an event to complete

    R- Runnable: Process is on run queue

    55

  • 8/10/2019 Solaris Users Guide

    56/166

    I- Idle: Process is being create.

    Z Zombie state: Process terminated and parent not waiting

    T Traced: Process stopped by a signal because parent is tracing it

    X SXBRK state: Process is waiting for more primary memory.

    Note that whilepsis running, the status of an individual process can change. Sincethepscommand gives you only a snapshot of what s going on at the moment youissue the command, the output is only accurate for a split second after you type thecommand.

    Theps(1) command has more options than those covered here. Refer to the manPages(1): User Commands.

    Terminating Processes (pkill)Most window environments have a tool for managing processes. See the tools onlinehelp if you need information on using it.

    You can use thepgrepandpkillcommands to identify and stop commandprocesses that you no longer want to run. These commands are useful when youmistakenly start a process that takes a long time to run.

    To terminate a process:

    1. Typepgreptofind out the PID(s) for the process(es).

    2. Typepkillfollowed by the PID(s).

    The following example illustrates how tofind all the processes with a specific name(xterm) and terminate thextermprocess that was started last.

    $ pgrep xterm17818178281775818210$ pkill -n 18210

    $

    If you need to forcibly terminate a process, use the-9option to thepkillcommand.

    $ pkill -9 -n xterm

    56 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    57/166

    Managing Disk StorageBecause space on the disk is a limited resource, make sure that you know the amountof space currently in use.

    Displaying Disk Usage (df -k)Thedf -kcommand displays the amount of space currently in use on each diskmounted (directly accessible) to your system. For the capacity of each disk mountedon your system, the amount of space available, and the percentage of space in use, usethedf -kcommand.

    $ df -k

    If the output of thedf -kcommand indicates yourfile systems are at or above 90percent capacity, clear unnecessaryfiles. Clear thefiles by moving them to a disk ortape, usingcpto copyfiles andmvto move them, or removing files with thermcommand. Perform these kinds ofhousekeepingchores only onfiles that you own.

    Displaying Directory Usage (du)You can useduto display the usage of a directory and all its subdirectories in units of512 bytes or characters.

    dushows you the disk usage in each subdirectory. For a list of subdirectories in a filesystem, change the directory to the path name that is associated with thatfile system.Then run the following pipeline:

    $ du | sort -r -n

    This pipeline, which uses the reverse(-r) andnumeric(-n) options of thesortcommand, identifies large directories. Usels -lto examine the size (in bytes) andmodification times offiles within each directory. Oldfiles and textfiles larger 100KBytes might warrant storage offline.

    Chapter 5Managing Processes and Disk Usage 57

  • 8/10/2019 Solaris Users Guide

    58/166

    58 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    59/166

    CHAPTER 6

    Using theviEditor

    vi(pronouncedvee-eye,short for visual display editor) is the standard SunOS text

    editor.viis not window based and can be used on any kind of terminal to edit a widerange offile types.

    You can type and edit text withvi, but it is not a word processor.vidoes not processformatted text in the familiar manner of a commercial word processor. To produceformatted printouts,virelies on a typesetting emulation program, such asnroff,troff, orditroff. These programs enable you to formatvitext by inserting codesthat are then interpreted by the emulator.

    viuses a variety of commands, many of which have functions that overlap. Thischapter provides an overview of the most essentialvicommands. As you begin to usevi, you willfind that it is an extremely powerful text editor, and proficiency happenswith practice.

    Note Theviewutility is a read-only version ofvi. When you open a file withview,you can usevicommands, but you cannot accidentally change the file by saving yourchanges.

    StartingviThe following sections describe how to startvi, type text in afile, save (write) thefile,and quitvi.

    59

  • 8/10/2019 Solaris Users Guide

    60/166

    Creating a File

    Startviand edit thefilepaintas shown in this example:$ vi paint

    Ifpaintalready exists,viopens the existing file. If this is a newfile,vicreates it. Forthe purposes of this example,paintshould be a newfile.

    Theviediting screen appears in a moment:

    ~~~~~~~~~~~"paint" [new file]

    Cursor

    Status line

    Blank lines

    FIGURE 61 vi Editing Screen

    The cursor appears in the upper left corner of the screen. Blank lines are indicated by avertical series of tildes (~).

    Note that you can also startviwithout specifying afile name by just typingvi. Youcan then name thefile later when you exitvi.

    Status LineThe last line of the screen, called the status line, shows the name of thefile and thenumber of lines and characters in thefile. When you create a newfile, as is the casewith the example, the status line indicates that it is a newfile.

    60 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    61/166

    Two Modes ofviTwo modes of operation inviare entry mode and command mode. You use entrymodeto type text into afile, whilecommand modeis used to type commands thatperform specificvifunctions. Command mode is the default mode forvi.

    Becausevidoesnt indicate which mode youre currently in, distinguishing betweencommand mode and entry mode is probably the single greatest cause of confusionamong newviusers. However, if you remember just a few basic concepts from thebeginning, you should be able to avoid most of the usualvi stress.

    When youfirst open avifile, its always in command mode. Before you can type textin thefile, you must type one of thevientry commands, such asi(insert), to inserttextat the current cursor location, ora(append), to insert textafterthe currentcursor location. These and othervientry commands are covered in greater detail laterin this chapter.

    Whenever you want to returnvito command mode, pressEsc. If youre not surewhich modeviis presently in, simply pressEscto make sure its in command modeand continue from there. If you pressEscwhileviis already in command mode, thesystem beeps and the screen flashes, but no harm is done.

    Entry ModeTo type text in the samplefilepaint, type theviinsertcommandi. This command

    removesvifrom command mode and puts it into entry mode.

    Now type a few short lines of text, ending every line with a Return. Characters youtype appear to the left of the cursor and push any existing characters to the right. Forthe moment, you can correct your mistakes by backspacing and retyping a line beforeyou press Return. For information on editing text invi, seeChanging Texton page 68.

    When youfinish typing text inpaint, press Esc to return to command mode. Thecursor moves back onto the last character you typed. Now you can type morevicommands.

    Ifviseems to act unpredictably, make sure that you are not in Caps Lockmode,which would cause your entries to be all capital letters. On some systems, the F1 key

    (usually next to the Esc key) acts as the Caps Lock. Pressing this key instead of Esc is acommon error.

    Chapter 6Using theviEditor 61

  • 8/10/2019 Solaris Users Guide

    62/166

    Note Occasionally you might need to instructvito clear or redraw the screen to

    eliminate, for example, extraneous system messages. To redraw the screen, entercommand mode and press Ctrl-L.

    Command ModeWhen you open afile withvi, you are in command mode. In this mode, you can typecommands to implement a wide range of functions. Mostvicommands consist of oneor two letters and an optional number. Usually, uppercase and lowercase versions ofcommands perform related but different functions. As an example, typingaappendsthefile to the right of the cursor, while typingAappends thefile at theend of the line.

    Mostvicommands do not require that you press Return to execute them. Commandsbeginning with a colon (:), however, do require that you press Return after thecommand. Some discussions of thevieditor refer to commands that are precededwith a colon as a third, and uniquely separate mode ofvi,last-line mode. This mode isso named because when you type the colon while in command mode, the colon andthe remainder of what is typed appear on the bottom line of the screen. For thepurpose of this discussion, however, allvicommands are initiated from commandmode.

    Commands that are preceded with a colon are actually ex commands.viandexaretwo separate interfaces to the same text-editing program. Whileviis a screen-orientedinterface,exis a line-oriented interface. The full set ofexcommands is available fromwithinvi. When you press the colon, you are actually switching to the line-oriented,exinterface. This switch enables you to perform manyfile manipulation commands

    without ever leavingvi. SeeUsingexCommandson page 71, in this chapter, forfurther information.

    Ending a SessionWhen you edit afile invi, your changes are not made directly to thefile. Instead, theyare applied to a copy of thefile thatvicreates in a temporary memory space that iscalled thebuffer. The permanent disk copy of thefile is modified only when youwrite(save) the contents of the buffer.

    This arrangement is both positive and negative. A positive feature is that you can quitafile and discard all the changes that you have made during an editing session,leaving the disk copy intact. The negative feature is that you could lose the (unsaved)contents of the work buffer if the system crashes. People on remote terminals that areconnected by phone lines are especially vulnerable to unplanned interruptions.

    62 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    63/166

    The best policy is to save your work frequently, especially when you are makingsubstantive changes.

    Caution Although its possible to run multiple, simultaneousvisessions on onefile,it is not a good idea. Great confusion could result when you try to determine whichchanges have been written to thefile and which changes have been overwritten from asimultaneous session.

    Saving Changes and Quittingviviis rich in substantively synonymous commands that control the save of the buffercontents to afile and the exit fromvi. These commands give you the option of saving,saving-and-quitting, or quitting-without-saving.

    Saving

    Save the contents of the buffer (write the buffer to the file on disk) by typing:

    :w

    Press Return.

    Saving and Quitting

    Save and quit by typing::wq

    Press Return. Alternatively, typeZZ.

    Note that the commandZZis neither preceded by a colon nor followed byReturn.

    Quitting Without Saving

    When youve made no changes to a file and want to quit, type:

    :q

    Press Return. If you have made changes,vidoes not let you quit with:q. Instead, itdisplays the following message.

    No write since last change (:quit! overrides)

    If you do not want to save your changes, type:

    Chapter 6Using theviEditor 63

  • 8/10/2019 Solaris Users Guide

    64/166

    :q!

    Press Return.

    Printing a FileAfter you quit avifile, you can print thefile with the following command:

    $ lp filename

    In this example,filenameis the name of thevifile to be printed. This command printsthefile to your default printer. The file is printed without any formatting, line for line,just as it appears on the screen. See Chapter 8 for more information on printercommands.

    BasicviCommandsThe following sections explain the following categories ofvicommands.

    Moving around in afile Inserting text Changing and substituting text

    Undoing changes to text Deleting text Checking your spelling Formatting yourfile output Repeating commands

    Moving Around in a FileIn the previous sections you learned how to create, save, print, and exit avifile. Nowthat you have created afile, youll need to understand the concepts that are requiredto navigate within it. Open your practice file now, and try each of the commands thatare discussed in this section.

    64 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    65/166

    Moving the Cursor

    When you startvi, the cursor is in the upper left corner of theviscreen. In commandmode, you can move the cursor with a number of keyboard commands. Certain letterkeys, the arrow keys, and the Return key, Back Space (or Delete) key, and the SpaceBar can all be used to move the cursor when youre in command mode.

    Note Mostvicommands are case sensitive. The same command typed in lowercaseand uppercase characters might have different effects.

    Moving With Arrow Keys

    If your machine is equipped with arrow keys, try these now. You should be able tomove the cursor freely about the screen by using combinations of the up, down, right,

    and left arrow keys. Notice that you can only move the cursor across already existingtext or input spaces.

    If youre usingvifrom a remote terminal, the arrow keys might not work correctly.The arrow key behavior depends on your terminal emulator. If the arrow keys don twork for you, you can use the following substitutes:

    To move left, pressh. To move right, pressl. To move down, pressj. To move up, pressk.

    Moving One Word

    Pressw(word) to move the cursor to the right one word at a time.

    Pressb(back) to move the cursor to the left one word at a time.

    PressWorBto move the cursor past the adjacent punctuation to the next or previousblank space.

    Presse(end) to move the cursor to the last character of the current word.

    Moving to Start or End of Line

    Press to move the cursor to the start of the current line.

    Press$to move the cursor to the end of the current line.

    Moving Down One Line

    Press the Return key to move the cursor to the beginning of the next line down.

    Chapter 6Using theviEditor 65

  • 8/10/2019 Solaris Users Guide

    66/166

    Moving Left

    Press the Back Space key to move the cursor one character to the left.

    Moving Right

    Press the Space Bar to move the cursor one character to the right.

    Moving to the Top

    Press H (high) to move the cursor to the top of the screen.

    Moving to the Middle

    Press M (middle) to move the cursor to the middle of the screen.

    Moving to the Bottom

    Press L (low) to move the cursor to the bottom of the screen.

    Paging and Scrolling

    If you move down when the cursor is at the bottom of the screen, or move up whenthe cursor is at the top of the screen, you will see the text scroll up or down. Thisscrolling can be an effective way to display more text in a short file, but it can betedious to move this way through a longfile.

    You can page or scroll backward or forward through a file, a screen or a half-screen at

    a time. To try out these commands onpaint, you might want to add text so you havea longerfile to work with.

    Note that paging and scrolling are fundamentally different. Scrolling actually scrollsthe cursor up or down through the texta line at a time,as though it were on a paperscroll. Paging moves the cursor up or down through the texta screenful at a time. On afast system, you might not notice the difference. However, if you re working from aremote terminal or in any other situation where your system is running slower thanusual, this difference can become painfully apparent.

    Page Forward One Screen

    To scroll forward (move down) one screenful, press Ctrl-F. (Hold down the Control

    key and press the F key.) The cursor moves to the upper left corner of the new screen.

    Scroll Forward One-Half Screen

    To scroll forward one half of a screen, press Ctrl-D.

    66 Solaris Advanced Users GuideMay 2002

  • 8/10/2019 Solaris Users Guide

    67/166

    Page Backward One Screen

    To scroll backward (that is., move up) one screenful, press Ctrl-B.

    Scroll Backward One-Half Screen

    To scroll backward one half of a screen, press Ctrl-U.

    Inserting Textviprovides many commands for inserting text. This section introduces you to themost useful of these commands. Note that each of these commands placesviin entrymode. To use any of these commands, you must first be in command mode.Remember to press Esc to make sure you are in command mode.

    Append

    Typea(append) to insert text to therightof the cursor. Experiment by moving thecursor any