Tutorial Week 11 - UNIX 3


Home


1. Log onto a UNIX workstation

2. Editing Commands

Commands typed in the terminal window can be edited.

Type the following commands

    history
    pwd
    du -s

Re-execute the pwd command. By specifying ! and how many commands ago it was.

3. Get the Date and Time

To check the current date and time, use the date command.

Alternatively a clock can be displayed. Run the xclock program by typing the command xclock.

4. Running Applications in the Background

Try and type something in the terminal window while the clock is displayed. The commands are ignored for the moment as the terminal (shell) is tied up running the current command - the clock. Close the clock. The commands typed in while the clock was running are now executed, and the terminal window will now accept commands.

This time run the clock in the background by placing an ampersand (&) after the command (e.g. xclock&). This runs xclock as a background process, and doesn't tie up the terminal window. Try typing some commands to confirm this.

Similarly when you use applications such as gedit, firefox etc, type the command then an ampersand, so that they run in the background. e.g. gedit& or gedit filename& or firefox&

Note: you can always open multiple Terminal windows as well, for example you might want to work in different directories at once etc.

5. Compile and Run the Program Hello.java

Change directory to the tutorials subdirectory of your Programming Environment directory.

List the files in the directory, the file Hello.java should be there from the last tutorial.

Before the program Hello.java can be run in needs to be compiled. To compile the program type the following command in a terminal window (exactly as shown):

javac Hello.java

List the files in the directory, what is the name of the new file?

To run the program type:

java Hello

More on Java programming in later lectures...

6. File Maintenance and Directories Practice

Copying Files

Copy the file Hello.java, giving the new file the name Hello2.java

Copy the file Hello.java, giving the new file the name Hello3.java

Move/Rename file

Rename (move) the file Hello2.java to the name Hello4.java

Move the file Hello4.java to your home directory, keeping the same name.

Move the file Hello3.java to your home directory, changing the name to Hello5.java.

Delete  file

Delete the file: Hello.class from your tutorials directory. This can be recreated by re-compiling Hello.java if it is needed.

While keeping the tutorials directory as your current working directory, delete the file Hello4.java from your home directory.

Change directory to your home directory and delete the file Hello5.java.

7. Check for Other Users

As you are already logged in to a UNIX workstation you can remote login to another UNIX computer using ssh (ssh is a secure remote login program unlike rlogin). Pick a UNIX workstation to remotely log into that already has someone logged into it e.g. ask the person next to you what indy they are using (to find out what workstaion you are on type the command: uname - n) or check the map on the notice board at the front of the classroom (if available). e.g. to remote login to indyf, type

    ssh indyf

or

    ssh indyf.bendigo.latrobe.edu.au

Then type in your username and password.

Check who else is using the workstation.

The who command shows information on the users using the system. Try it. It should look something like:

tim     ttyq0 May 4 22:43 (whitfort.bendigo.latrobe.edu.au:0.0)
afsmith ttyq2 May 7 13:15 (:0.0)

Description

tim           Username
ttyq0         Terminal line
May 4 22:43   Date and time logged in 
(whitfort.bendigo.latrobe.edu.au:0.0)  The computer user is logged in from. 

In the above example the user afsmith is sitting at the Unix workstation.

For more information on what users are doing on the system you have logged into, use the w command. Try it. It should look something like:

 1:59pm up 6 days, 23:01, 2 users, load average: 0.02, 0.04, 0.00
User    tty from           login@  idle JCPU PCPU what
tim     q0  whitfort.bendi Sun10pm      3:38      w
afsmith q3 :0.0            1:15pm  1      22      gedit Page1.html

Description

The first line describes statistics on the system e.g. the current time is 1:59pm, the system has been up (on) for 6 days, it has 2 users etc.
The first 4 columns are similar to those described in who. The idle column shows the time (as minutes, or hours:minutes) since there was any user input, the JCPU column shows the total CPU time (as seconds, or minutes:seconds) of all jobs run by the user, PCPU column shows the CPU time (as seconds, or minutes:seconds) taken by the current job, and the what column shows what the users are doing e.g. what they are running.

Log off the remote workstation

8. Top Users

The top command shows the top users of the workstation. The %CPU column shows the percentage of CPU time used by a process. If your workstation is running slowly, top can be a useful tool in determining what is using up CPU time. Maybe it is you (e.g. infinite loop is a program) or another user.

Try typing the top command at the console. Run firefox at the same time. Notice the change in CPU usage as firefox starts up and is used.

Type Q to quit top.

9. Preferences

Investigate the system preferences to change your screen background etc:

Select System > Preferences

10. Investigate Further

11. Log off


Written by Tim Whitfort.