Computer Lab Week 10 - UNIX 2


Home


1. Go to the Linux UNIX lab (B1.11)

2. Log onto a Workstation

3. Complete the previous tutorial if you haven't already.

4. Open a Terminal Window

5. Create a Directory for Programming Environments

Refer to the lecture notes where necessary to find out how to do the commands used in this tutorial.

List the files in your home directory.

Create a sub directory for Programming Environment. Short meaningful names are best as you end up typing them a lot e.g. pe, progenv, PE or ProgEnv

To create a subdirectory use the mkdir (make directory) command. Type the following command substituting an appropriate name for the directory:

    mkdir ProgEnv

List the files in your home directory. A directory for programming environment should now appear.

Change directory to your new Programming Environment directory. To do this use the cd (change directory) command. Type the following command substituting an appropriate name for the directory:

    cd ProgEnv

List the files in your programming environment directory. It should be empty. Now list all of the files in the directory (what command option is used for this?). The "." and ".." should be listed.

The programming environment directory (folder) is to help organise your work, in future put all work for Programming Environment in this directory.

6. Create Directories for Tutorials and Assignments

Create a sub directory in the Programming Environments directory for your tutorials.
Create a sub directory in the Programming Environments directory for your assignments.

Draw your new directories on the following directory tree:

Example: Directory tree (partial)

           /
           |
 +----+----+----+----+
 |    |    |    |    |
bin  dev  etc  tmp Users
                     |
                     |
          +----------+----------------+
          |                           |
        cjcope
          |
 --+------+-+---------+
   |        |         |
Pictures  Public     Music
            |
            +--------+--------
            |        |
      Welcome.java  lecture17.html

7. Directory Paths

Use the directory tree above to help with the following questions.

Write the paths for the following:

  1. When you log in, what is your present working directory?
  2. What is the path to your home directory?
  3. What is the absolute path to your tutorials directory?
  4. What is the relative path to the Users directory (present working directory is your home directory)
  5. What is the absolute path to cjcope's Public directory?
  6. What is the relative path to cjcope's Public directory (present working directory is your home directory)

Write commands for the following, then try them:

  1. Write a command that changes directory to your home directory. Try it.
  2. Write a command that gives a long listing of all of the files in the current directory. Try it.
  3. Write a command that uses an absolute path to list the files in your tutorials directory. Try it. This should be empty.
  4. Write a command that uses a relative path to list the files in your tutorials directory. Try it.
  5. Change directory to your tutorials directory.
  6. Write a command that uses a relative path to list the files in the Users directory . Try it.
  7. Write a command that uses an absolute path to list the files in cjcope's Public directory. Try it.
  8. Change directory to the Users directory.
  9. Write a command that uses a relative path to list the files in cjcope's Public directory. Try it.

8. Viewing Files

Change directory to your tutorials directory.

List all of the files in cjcope's Public directory.

Copy the file Welcome.java from cjcope's Public directory to your tutorial directory using an absolute path. Have a look at the directory tree drawn above to see where the file is located. Type the following command, making sure you include the dot at the end:

    cp /Users/cjcope/Public/Welcome.java .

Also copy the file lecture17.html from cjcope's Public directory to your tutorials directory.

View Welcome.java using cat.

Have a look over the program. It looks different to Visual Basic, but as you'll see in later lectures many of the things learnt in earlier lectures on VB will be applicable to Java. The program just displays the message "Welcome to Java programming".

View the file using less.

Now lets try a longer file to see the difference between cat and less.

View the file lecture17.html using cat

View the file lecture17.html using less. Try the less commands shown in the lecture. e.g. use the space key to move forward one window of text at a time. Use q to quit (exit more).

Some commands are shown below. Try them.

9. Setting Preferences in gedit Editor

gedit is a useful text editor. Text editors can be used to create source code for programs or web pages. gedit provides are number of features that are useful to programmers. Set the preferences for gedit as specified in the lecture. Remember you can use firefox to view the lecture notes, tutorials etc..

10. Using gedit

Open the file Welcome.java using gedit.

The name of the file is displayed in the title bar of the gedit window.

Change the comment for the Author to your name.

Change the "Welcome to Java programming" message to "Hello World".

Notice that an "*" appeared in front of the file name in the title bar. This shows that changes to the file haven't been saved yet.

What is the shortcut key for Save?
Save the changes, using the shortcut key for Save. Check that the * disappeared from the title bar.

What are the shortcut keys for Cut, Copy and Paste?
Use the shortcut keys to Copy and Paste the line commencing System.out.println, so that it appears 5 times. .

Save the changes.

Exit gedit

11. Further Investigation

Further investigate the commands covered in the lecture.

If you haven't set up a web browser, see the previous tutorial and set one up. Have a browse.

12. Log out


Written by Tim Whitfort (and Chris Cope).