Sunteți pe pagina 1din 6

Introduction to Unix - Lab Exercise 0

Along with this document you should also receive a printout entitled First Year Survival
Guide which is a (very) basic introduction to Unix and your life in the CSE labs. It was
written in a hurry so if there is anything you feel should be included please let us know
by emailing compsoc@cse.unsw.edu.au. This series of exercises is relatively short and is
intended just to get you up and running. Refer to the guide and the Unix Primer for more
detail. For those of you that have done the maths department introduction, much of the
same thing will be covered here so you can skip straight to the exercises.

Logging In

When you sit down you will see a window asking for your login and a password. At
the login prompt type in the login name that you were given when you first enabled your
account: it should be a sequence of a few letters followed by a few numbers.

For example, a student named Jane Smith might have the following login:

janes747

This is your login name for the CSE network computers. Next, hit enter and type your
account password into the box to the right of the password prompt, which is the same
one you entered into Sirius when you enabled your account. You will notice that unlike
your login, your password does not show up on the computer monitor: this is normal, as
your password should not be seen by others around you. Now hit enter once again, and in
a few moments you will be logged into your account for the first time.

If you havent enabled your account yet please see your demonstrator - he/she will be able
to log you into a temporary account so you can still do the exercises.

Entering Commands

You should now see two large xterm windows in front of you. These are windows into
which you type commands to be run by the computer. You will also see a small window
in the upper left of the screen. You can safely ignore this for now. If you click any of the
3 mouse buttons in the background you will see a menu pop up. Each of these buttons
brings up a different menu and the menus will be explained in more detail during your first
lab.

1
Move your mouse into the larger of the two windows - see how it changes colour? This
means that this window is now the active window and all commands you type will show
up here. If you knock the mouse out of a window the keyboard wont be entering text into
that window anymore.

You will see a prompt in the upper left corner of the xterm. It will probably be a
percentage sign (%). This is the xterms way of saying give me something to do. You
can type commands in here and the xterm will execute them for you.

Lets try a simple command now. Type whoami at the prompt and hit enter. This should
print out your login name.

%whoami
janes747

Not too difficult, was it ?

Every command you type in Unix is the name of a file to execute. In the previous example
we executed a file called whoami which prints out your userid. There are many commands
on this system and we cant hope to cover them all here, but well plunge on into a few of
the more basic ones.

Basic Lab exercise

Just follow all the commands as illustrated throughout. It should be self-explanatory but
there will be demonstrators around to help you if you have a question at any time.

When you start you will be in your home directory. This is your little space in the memory
storage of CSE. It is limited, so be careful not to overfill it. You probably wont have any
files in your account yet, so lets see what we do have.

To list all the files in the current directory we use a command called ls (list). Lets try
that now:

%ls
public_html

This means that the account has been created with this directory (or folder) public html
already there. Other than this, you have no files. Or do you ? ls has options that will
alter the way it runs, as do most of the other commands.

Unix supports hidden files that start with a dot (.). To view them we run ls with the
-a option to list all the files in the current directory. Lets try this now:

2
%ls -a
.Xauthority
.login
.profile
.withenv
public_html

These files are usually just configuration files for programs and you can safely ignore them
for now. There are other options to ls which you can find out about later. The only
other one you may want to try out now is the l option which is illustrated in the Compsoc
Survival Guide.

Lets create a directory of our own. The command mkdir (make directory) will do this
for us. Lets try to create a directory within the current directory called test:

%mkdir test

Now list the contents of the directory again:

%ls
public_html test

We can now see that we have two directories in our account: public_html and test.
So how do we move into this new directory ? This is accomplished with the cd (change
directory) command:

%cd test
%ls
%

This directory is empty, as you can see. At any point, you can type cd .. (note the space
character) to move back a directory level. To find out where you are currently working,
use the pwd (print working directory) command:

%pwd
/import/bizet/2/janes747/test

Dont worry about the /import/bizet/2/ part yet - this is just the location of your home
directory on the CSE system. Lets now create a file called test1. We will be creating
this file with an editor called nedit. You will get more information soon about the full
operation of this editor. Lets run this editor now:

%nedit test1

3
This will bring up a new window. There will be a prompt accompanying this window
which will tell you that the file called test1 does not exist, and asks you whether you
would like to create it: click on the Create button to create the file.

Type some text in the window (whatever you like) and then save the file. You do this by
clicking on the File menu and selecting Save. Once you have done this, exit the editor
by choosing File and then Exit.

%ls
test1

We now have a new file called test1. How do we view this when were not running an
editor ?

There are two main commands for this: cat and less. The difference between them
is that cat simply prints out the whole file, while less lets you view the file page by
page. Lets see how these work:

%cat test1
This is the text I
just typed into the editor

less has a few commands which allow you to either move forward or backward through
the file, search for text or go through the file line by line. To simply scroll through the
file page by page, just keep hitting the spacebar. To exit less you just type q at any
time.

Lets see some other basic file operations:

%mv test1 test2


%ls
test2
%cp test2 test3
%ls
test2 test3
%cat test2
This is the text I
just typed into the editor
%cat test3
This is the text I
just typed into the editor

You can see that the command mv (move) will rename a file and the command cp
will copy a file. Further usage of these commands are illustrated in the Compsoc Survival

4
Guide.

Now theres just one last thing we need to be able to do: delete files. Remember that
all deletions in Unix are permanent - there is no undelete ! The command rm
(remove) will do this for us.

%rm test2
%ls
test3

We can remove directories with the command rmdir. The directories need to be empty
of all files for this command to work, though.

%mkdir removeme
%ls
removeme test3
%cp test3 removeme
%cd removeme
%ls
test3
%pwd
/import/bizet/2/janes747/test/removeme
%cd ..
%pwd
/import/bizet/2/janes747/test
%rmdir removeme
rmdir: removeme: File Exists
%rm removeme/test3
%rmdir removeme
%ls
test3

We have created a directory call removeme, copied our file into it and then tried to remove
the directory. This didnt work because the directory was not empty, so we removed the file
from the removeme directory, which then allowed us to remove the now empty directory
successfully. You should be left in your test directory with one file called test3.

5
Before we leave, lets clean up after ourselves:

%rm test3
%cd ..
%rmdir test

Well, you have now successfully navigated the basic unix commands. Make sure you read
the Compsoc Survival Guide as this will give you much more detail and more commands
and options than this basic introduction. Hopefully you will have learnt enough to start
trying commands out on your own - good luck!

Please at least read the section in the Compsoc Survival Guide about reading
email - you need to be able to do this every time you log in since most of the
important subject details and updates will be communicated through email.

Please get a demonstrator to sign below and take this to your computing tutor in week 2
to get marked off and get a little more credit.

Name SID Demonstrator Name Demonstrator signature

S-ar putea să vă placă și