UNIX Basics
  1. Conventions

    Italic text indicates text displayed by the computer system. For example,
    login:
    indicates a login prompt displayed by the system. If you see bold text. You type the text exactly as shown. For example,
    more file_name
    means that you type more followed by a file name of your choice.
    < keys >You type the corresponding key on the keyboard. For example, <Ctrl-D> means you hold down the <Ctrl> key while pressing the <D> key.
    [...]Represents the optional items in a command-line entry.

  2. File System

    UNIX has a hierarchical file system which looks like an inverted tree structure. The top of the file system is called the root directory and is always indicated with a forward slash (/). Under the root directory are the sub-directories and files.

  3. Case Sensitivity

    UNIX interprets capital (uppercase) and small (lowercase) letters differently. For example, if a user logs in with capital letters for his/her login name which should be in small letters, the login will not be successful. Most UNIX commands should be entered using small letters

  4. File and Directory Names

    They can be up to 256 characters long, and can be composed of upper and lower case letters, digits, underscore, period, and comma.

  5. Command Convention

    All UNIX commands have a general format as:
    cmdname [-abc.....] arg1 arg2 ... argN

  6. Connecting to UNIX

    1. In WinXP/Win98, choose Command Prompt to use the Dos command environment. Type the command
      telnet personal.cityu.edu.hk
    2. As soon as the connection is made, The remote host login prompt will be displayed.
    3. You should log in by typing your user name terminated by . Then your password when the password prompt appears.
    4. Once logged in, you will see some greeting messages and a sommand prompt moscow% indicating that the system is ready to accept commands.


  7. Logging out from the System

    When you have finished working on UNIX system, type logout at the system prompt. And close the telnet and Command Prompt windows.

  8. Changing Your Password

    Users are advised to change their passwords from time to time to increase the system security. Use the command passwd for this purpose. When changing a password, passwd prompts for the old password and then for the new one. The new password must be typed twice to avoid making mistakes. The password typed in will not be echoed on the screen. A password must contain at least two alphabetic characters and at least one numeric or special character within the first eight characters. If no errors occur, your screen should look like this:
    	moscow%passwd
    	Old password:
    	New password:
    	Re-enter new password:
    	moscow%
    


  9. How to Get On-line Help

    UNIX commands and system calls are documented thoroughly in the UNIX Reference Manuals. In addition, UNIX can also store reference manual pages (commonly known as man-pages) on disk. If your system has these 'on-line' man-pages, you can use the man command to display them on screen. The man command displays a command's syntax along with a detailed description of the command and its options and arguments (if any). In addition, man may display examples of command usage and provide other information such as system files used, related commands, diagnostics, possible problems (bugs). Syntax: man [[section] title ...] ... For example, using man, you can learn more about the man command itself: moscow$ man man
    You can:

    Step through the file a page at a time by pressing the space bar.
    Scroll through a line at a time by pressing <Return>.
    Quit viewing the reference page by pressing <q>.


    To learn about the Java compilation system, type:

    moscow$ man javac
    moscow$ man java

  10. The cat command - concatenates and displays

    Syntax: cat [options] [filename ...]
    Characteristics:
    • the most basic file display command
    • good only for displaying small files as it scrolls to the end
    • for ASCII file only, but will attempt to display anything
    By default, the standard input of a process is the keyboard and the standard output is the screen. We can send the standard output of a process to a file instead of the screen by making use of a shell facility called output redirection. If you follow a command by a '>' character and the name of a file, the output of the command is written to the file. If the file doesn't already exist, it is created, otherwise, its previous contents are overwritten. cat reads each file in sequence and writes it on the standard output. Thus,
    moscow$ cat file
    prints the contents of file on your terminal, and
    $ cat file1 file2 > file3
    concatenates file1 and file2, and writes the results in file3. If no input file is given, cat reads from the standard input.

  11. Using cat to create HelloWorld.java file
                    moscow% cat >  HelloWorld.java <Enter>
                    public class HellowWorld {<Enter>
                       public static void main(String[] arg) {<Enter>
                          System.out.println("Hello World");<Enter>
                       }<Enter>
                    }<Enter>
    		<CTRL D>
    


  12. Vi - invokes the visual display editor

    Before you can use the Vi editor, which is a screen-oriented text editor, you need to set the terminal type with the following commands:

    moscow% TERM=vt100
    moscow% export TERM

    Syntax: vi [options] filename
    Characteristics:
    • Creates new files or modifies existing files.

    • 2 basic modes of operation: the command mode and the insert mode (text input mode).
    • The key has a special meaning to vi in both modes:
      • command mode - cancels vi commands
      • insert mode - terminates insert mode
    • Most commands are single letters.

  13. UNIX Command Reference
  14. vi Command Reference


Part 3 Programming exercises.

  1. Given the following Java program:
    /*               Program CirArea.Java                 	**
     **                                                     **
     ** This program asks the user to input a decimal       **
     ** number for the radius of a circle.  The program     **
     ** then calculates the area of the circle.             */
    
    import java.io.*;
    
    public class CirArea  {
        public static void main(String[] arg) throws IOException {
           float area ;
           int r  ;
           final float pi=3.14f ;
    
           System.out.println("Please enter radius in whole number: \n") ;
           r = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine());
    
           area = pi * r * r ;
    
           System.out.println("The radius you provided was " + r + " feet and  the area is about " + area + "sq feet");
         }
    } 
    
  2. Enter, compile and run the above program in the Unix environment.Thus:

    moscow%vi CirArea.java
    moscow%javac CirArea.java
    moscow%java CirArea