Using HP-UX


Use this as a short reference for the HP Unix system at MWC.
Please remember that Unix is case sensitive. Upper case and lower case letters are not the same.

I. Accessing the System


A. To begin a session use:

B. Changing Your Password

  1. At the $ prompt enter: passwd
  2. Enter old password in response to prompt old passwd:
  3. Enter new password in response to prompt new passwd:
    Reenter new password for verification
    **Do not use the #, @, $ or the \ in your password.**

C. To terminate the current session:

exit or click on the exit sign

D. To obtain on-line help use:

man command
If you are unsure of the exact command name use:
man -k command

E. To determine your pathname at the $ prompt enter:

env

F. To see the absolute path name of the current directory at the $ prompt enter:

pwd

G. To echo the screen contents to a file at the $ prompt enter:

script filename
(Continue with what you want to echo to the file.)
To terminate this echo at the $ prompt enter: exit

H. To close all open files at the $ prompt enter:

sync

II. File Management

A. To display a list of file names use:

ls, ll, or Ls -a

B. To display the contents of a file use:

more filename
RETURN displays next line, q terminates display,
space bar displays next screen.

C. To delete a file use:

rm filename

D. To rename or move a file use:

mv currentfilename newfilename

E. To copy a file use:

cp source_file destination_file

F. To combine two or more files use:

cat file1 file2 ... > combo

G. To append a file to another file use:

cat sourcefile >> destinationfile

H. To terminate a Unix command or an executing program use:

CTRL-C
( hold down the control key and press the key C)

III. Managing Directories

A. To create a subdirectory use

mkdir Name_of_Directory

B. To change to a subdirectory use

cd Name_of_Directory

C. To move to the parent directory use

CD ..

D. To return to your home directory use

CD

E. To delete a directory you must first delete all its files:

Use rm *.* to do this; then use CD .. to move to the parent directory; then use rmdir Name_of_Directory to delete the directory itself.

IV. Print Commands

A. To obtain a printout of your file use:


cat filename | lp
or spool filename
(The output will be printed on the printers in B14.)

To obtain a printout of your file including line numbers use:


cat -n filename | LP

B. To view current print buffer use:

lpstat
(Each job under your username will be listed with a
print id e.g. matrix_1023.)

C. To cancel a print job use:

cancel print id
e.g. cancel matrix_1023
(Use the printid as displayed using the lpstat command.
The printer must be online for this command to be
effective.)

 

V. The vi Editor

A. File creation

  1. At the $ prompt enter
        vi

  2. You will then see an empty workspace
  3. Press the the A key to allow you to enter text. Pressing A puts you into append mode.

  4. Be sure to press Enter at the end of each line

  5. To save a file:
    a. Press the ESC key to switch to command mode
    b. Enter a colon (:). The cursor will move to the command line at the bottom of the screen.
    c. Enter wq filename.cpp (press Enter)

  6. To periodically save your work:
    a. Press the ESC key to switch to command mode
    b. Enter :w filename.cpp (press Enter)

  7. Continue entering and saving text as necessary. When you save a file this way the previous version is replaced.

  8. When you're done press ESC and enter :wq filename.cpp (Press Enter)to save the current workspace and exit vi.

  9. To exit vi work session without saving current workspace press ESC and enter :q!

B. File Modification Using the vi Editor

  1. Enter vi by entering the following at the $ prompt: vi full_file_name

  2. Moving cursor around the screen

    To end of current line use: $
    To start of current line use: 0
    up, down left, right use arrow keys OR k , j, h, l
    To end of file use: G
    To first line of file use :1 ENTER

  3. To advance to next page use pgdown.
    To go back to previous page use pgup

  4. To display line numbers enter:
    ESC colon (:), set number , ENTER

  5. To move cursor to a specific line enter
    ESC colon(:), line_number, ENTER
    e.g. ESC:15 ENTER

  6. To insert text to left of cursor, enter i followed by text to insert.
    To insert text to right of cursor,enter a followed by text to insert.
    Lines may be inserted by following the same sequence and pressing ENTER as appropriate.

  7. To delete character at cursor use x

  8. To delete line containing cursor use dd
    To delete several lines from cursor line on use:
    #_of_linesdd

  9. To replace character at cursor use r newch
    To substitute more than one character for character at cursor use s newchars

  10. To replace all occurrences of a text pattern with another use
    :g/text_pattern/s//replacement_pattern/g

  11. To search file:
    Forwards from cursor use /pattern ENTER
    Backwards from cursor use ?pattern ENTER
    To repeat previous search command use /ENTER

  12. To join current line with next line use J

  13. To move a block of text
    -Position cursor at start of block
    -remove block with #_lines_in_blockdd e.g. 10dd
    -reposition cursor
    -press lowercase p

  14. To copy a block of text
    -Position cursor at start of block
    -copy block with #_lines_in_blockyy e.g. 12yy
    -reposition cursor
    -enter lowercase p

  15. Enter % with cursor on a (,),{,},[,] to find its mate.

VI. Electronic Mail Using elm


A. Accessing Your Incoming Mail


1. Enter elm to the $ prompt.
2. Follow on-screen instructions to access and delete current
messages.
3. To save current message enter: s and then provide
an appropriate filename for storage. (Backspace over
any default name not desired by you.)


B. Sending and Creating a Mail Message


1. While in elm, select the M)ail option
2. You will then see an empty workspace
3. Depress the letter a to allow you to enter text
Be sure to press ENTER at the end of each line
4. Use this sequence to retain a permanent copy of the file just
created.


a. Press ESC to switch to command mode
b. Enter a colon (:). The cursor will move to the command line at
the bottom of the screen.
c. Enter wq ENTER **DO NOT APPEND A FILENAME!**


5. You have now been returned to the elm menu

C. Message Modification


1. This may be done after pressing ESC (see 4b above)
and prior to entering :wq (see 4c above)
2. Use the vi commands as described above

Using the C++ Compiler on Paprika

VII. Using C++ on the HP System


A. Creating a C++ Program File

  1. Login as usual
  2. At the $prompt type vi yourfilename.cpp
  3. When the empty workspace appears, press a to go into "append" mode so what you type is put into the workspace.
    Continue to enter your source program.
    You must press ENTER to move the cursor to the next line.
  4. Type each line as needed. The vi editor will automatically indent each line to align with the previous line. Press TAB to indent and CTRL-D to move back one tab.
  5. After completing the entry of your program, press ESC and then enter :wq

B. Compiling a C++ program

  1. At the $ prompt start a script file and invoke the C++ compiler
    by entering
         script listing
       cpp yourfilename.cpp -o yourfilename.R
       exit
  2. These commands will result in the following:
    Your source program (yourfilename.cpp) is examined for syntax errors by the compiler and if there are any they are displayed on the screen and copied to the file named listing.
  3. You can print the file named listing by entering
        LP listing
  4. If there are no errors then the file machine language file yourfilename.R is created. It contains the executable version of your program.
  5. If your source file contains syntax errors then use the vi editor to correct them. Enter
        vi yourfilename.cpp
    Save the modified version using :wq
    Go back to step 1 in this section.

C. Executing a program

  1. If your program compiled (if there were no errors reported in the steps in the previous section) then an executable program was produced. To execute it, at the $prompt enter
           yourfilename.R
  2. If your program fails to run to completion, doesn't stop running, or otherwise fails to run as you expect then you're going to have to find the source of the problem.
    Try reading the source file again to see if you can spot a flaw in the logic.
    Another way to approach this problem is to put cout statements at strategic points in your program and noting where execution was suspended.
    Modify the source file by using the vi editor, as described above, to correct the situation.
  3. If your program runs to completion then examine the results to verify that the program yields correct results. If there is problem then you'll have to reread the source, use cout statements and vi as described above.

D. Preparing your assignment for submission

  1. Compile your program using
    cpp yourfilename.cpp -o yourfilename.R
  2. Open a script file to capture the results
    script results
  3. Execute your program
    yourfilename.R
  4. Close the file opened with script
    exit
  5. Append line numbers to your source file using
    cat -n yourfilename.cpp >> results
  6. Print
    LP results

VIII. Accessing the HP-UX System on Campus Using Eaglenet and
MS-Windows


A. Login to paprika
1. Select Start, Run
2. Enter Telnet paprika.mwc.edu
3. A window will open and you will be prompted for your HP-UX ID
4. Enter your HP-UX login ID and HP-UX Password
B. Exit Paprika
1. To the $ prompt, enter exit [return]
2. Connection to host is terminated
3. Close Telnet window
C. To Transfer Files Between a PC and the HP-UX System
1. Select Start, Run
2. Enter Ftp paprika.mwc.edu
3. A window will open and you will prompted for your HP-UX ID
4. Enter your HP-UX login ID and HP-UX Password
5. Enter ? to get a full list of available FTP Commands
6. Some useful commands are:
a. lcd will change the directory on the PC
b. CD will change the directory in your HP-UX Account
c. put local_file will copy "local_file" to your account
d. get file_name will copy "file_name" from your Unix Account
to your PC.
e. bye will terminate the ftp session.

IX. Remote Access to the HP-UX System Using Eaglenet and Windows


Sometimes the B13 lab may be crowded. Sometimes you may want to work on your program late at night and not feel like walking all the way over to Trinkle. Remote access to paprika is the answer.

If you intend to use Telnet to gain remote access to the paprika system, you must use the vi editor. It is the only
editor that functions within a remote login environment. This is one of the reasons that it is a good idea to be able to use the vi Editor!

I recommend using an enhanced Telnet program like Teraterm Pro. This program is free and provides a cleaner interface than standard Telnet programs.

You can download this program onto your own PC from the following website:
http://software.wm.edu/win-internetnav.html
The download that you want is called "Teraterm Pro 32 bit". Just click the link to download the file
TERMP23.EXE. Put it in a temporary directory and double click on it to unpack the installation files.

A. TeraTerm Pro version 2.3 (32-bit) Installation Notes
Run setup from the unpacked files to start installation
Click continue with English as the desired language
Click continue on the setup note (teraterm not currently running)
Click continue to accept the default install directory
Click OK on the setup complete screen.
Double click on the icon TeraTerm Pro to run the program the first time.
The general setup window will appear. Choose TCP/IP as default port.
Click OK.
The new connection window will appear.
Type in the Internet name of the computer to which you want to Telnet
(E.g. paprika.mwc.edu)
Choose OK to connect and then log in.
To add computers to the new connection window:
choose setup
choose TCP/IP
type Internet name of computer in host name box (e.g. paprika.mwc.edu)
choose add
choose ok
that computer will then be in the list for login.

B. Using Teraterm to connect to paprika
If you are off-campus then you need to dial-in and login with your Internet provider.
After a successful dial up and login you are ready to use Teraterm.
Using teraterm:
Double click on the program icon for TeratermPro
A login screen will appear asking for the host name. Enter: paprika.mwc.edu
A window will appear that will request your Eaglenet login and password, after this completes, you will be
asked for your paprika login and password.
A Unix screen will appear and you're ready to work just as if you were in the B13 lab!

C. To logout of paprika
At the Unix $ prompt type
exit [then press Enter]. The connection to host is terminated. Close the window.

D. To Transfer Files Between a PC and the HP-UX System
On your Windows machine, Select Start, Run
Enter ftp paprika.mwc.edu
A window will open and you will be prompted for your paprika user id. Enter your user id and password.

You may enter the character ? to get a full list of available FTP Commands. Some useful commands are:
? LCD will change the directory on the PC
? CD will change the directory in your HP-UX Account
? put local_file will copy "local_file" to your account
? get file_name will copy "file_name" from your Unix Account to your PC.
? bye will terminate the ftp session.

E. Using MS-Word to Prepare a File For Use On Paprika
After you feel comfortable using the vi Editor, you may wish to use MS-Word to type your initial program file.
You enter the text as you would for any other document. Paprika cannot interpret .doc files. To save a file in a
format usable by Paprika you must use File, Save-As, Save as Type: Text Only With Line Breaks, File Name:
"your_file_name.cpp" , then click Save. You must include the " (quotes) otherwise the system will append .txt
which is again not appropriate for Paprika. After creating and saving your file on your PC you can transfer it to
your Paprika account using ftp as explained previously.

You can get handouts with additional information on making remote connections in the lab aid office (usually they
have handouts posted on the door at the beginning of the semester).