CS354

Tutorial 1: Using the UNIX Environment

Goal

In this lab you will:

Procedure

Step 1. Get your computer accounts

You will need an account in this course for the computer mentor.cc.purdue.edu that is administered by PUCC (Purdue University Computer Center). You will login into this computer remotely to compile your programs.

Before you go to your lab time make sure that you know the login and password for mentor. This is the same account and password that you use for the PCs in the Purdue computer labs. If you don't know your PUCC login and password go to MATH-231 to get it before your corresponding lab time.
 

Step 2. Login into mentor

Click the icon in the screen that is labeled "mentor". This icon is going to connect to the computer mentor.cc.purdue.edu. Type your PUCC login and password.
login: <your-pucc-login>
Password: <your-password>

Step 3. Change your current shell to tcsh

The default shell that you use in mentor is called "csh" (pronounced Ce shell). This shell does not have line editing, so we recommend you to switch to tcsh (pronounced Te Ce shell) instead. Type the following to switch your current shell to tcsh. Type the following:
 
mentor.cc.purdue.edu% chsh
Changing login shell for <your-login> on *all* ACMAINT hosts.
Old shell: /bin/csh
New shell [/bin/csh]: /usr/local/bin/tcsh
Now logout typing
mentor.cc.purdue.edu% exit
Repeat Step 2 to login into mentor again. After you login you should obtain a ">" prompt that is the tcsh prompt.

Step 4. Simple UNIX commands

The most common used command is "ls".  Type:
> ls
The command "ls" with no arguments lists the contents of the current directory. If you want to see the details of the files type:
> ls -al
The command "pwd" prints the directory path of the current directory. This current-directory is the directory where the shell is currently in. Type:
>pwd
/home/lookout/<some-letter>/<login>
The directory path  printed is a list of the directories necessary to reach the current directory from the root directory.

To create a new directory (for example the cs180 directory) type:

> mkdir cs354
> ls
To change the current directory to the cs180/ directory type:
> cd cs354
> ls
You will notice there are no files in there. Now type:
> ls -al
You will see two files: "." and ".." One dot means the current directory and ".." means the parent directory.

To change the current directory to the parent directory type:

> cd ..
The home-directory is the directory where all your files are stored and is where the current-directory points to when you login. To change the current directory to your home directory type "cd" with no arguments. Type:
> cd
> pwd
> ls
Sometimes you would like to go back to the previous command. To do that in tcsh type the <up arrow> (the key that has the arrow pointing upwards). Type:
> <up arrow>
several times and you will get the last commands. To execute the current command displayed type <ENTER>. You may also type the <down-arrow> to go to the next command.

For example, type <up-arrow> until you find the "ls -al" command and then type <ENTER>.

If you have committed an error while typing, you may use the <left-arrow>,  <right-arrow>, or <backspace> to move the cursor and correct it.

You don't need to type all the characters for a file or command. You may use <tab> and <ctrl-d> to complete the name of a file.

For example, type:

> ls /usr/j<tab>

This will complete to "ls /usr/java"

If the prefix matches several files, you may see a list of files matched by typing:

 > ls /usr/p<ctrl-d>

This will show all the files that start with "/usr/p"

Also you can reffer to a list of files by using the character "*". The "*" character in a file name represent one or more characters. For example:

> ls /usr/lib/*.a

Lists all the files that end in ".a" in the directory /usr/lib.

Here is a summary of the commands you have learned and some more:
 

Summary of UNIX commands

ls Lists the contents of the current directory
ls -al Lists the contents of the current directory in detail
pwd Prints the path of the current directory
mkdir new-directory Create a new directory
cd directory-path Change to a directory
cd Change to home directory
cp old-file new-file Copy a file from old-file to new-file
mv old-file new-file Rename a file from old-file to new-file
rm file Remove a file
echo "message" Outputs the string "message" 
<up-arrow> Get previous command
<down-arrow> Get next command
<left-arrow>, <right-arrow> Move cursor to the left or rigth.
<tab> Path-completion

Step 6. Running xterm

The xterm program is similar to telnet but has other flexibilities such as window-resize. To run xterm type:
> /usr/openwin/bin/xterm -sb &
The "-sb" option is for scroll-bar and the "&" is to run xterm in the background. Running a program in the background means that the shell will return a prompt immediately and will not wait until the program completes.

You may open as many xterm windows as you want using the command above.

Step 7. Running xemacs

We strongly recommend you to use xemacs to edit your files. xemacs is a professional editor for the UNIX environment. To run xemacs type the following from the xterm window.
>/opt/SUNWspro/bin/xemacs &
This command will run xemacs in the background. You will see the xemacs window appear on your screen.

You can use xemacs using the pull-down menus like other editors with a graphical user interface. If for some reason you are stuck in the prompt at the bottom line type <ctrl-]>