Introduction To Unix Tutorial: CSIF Computer Network
Introduction To Unix Tutorial: CSIF Computer Network
Local Logging In
If you are taking a computer science class, you will automatically get an account on the CSIF machines. This
means you can log in to any of the machines in the basement labs. To access an account, you will need two
things: 1) your Username and 2) your Password. Your user name is your UCD Kerberos username, and your
password is your kerebos password.
Type your login name, then your password. Do this now. If all goes well, the monitor will display the UNIX graphic user
interface (GUI) of the computer for you.
The PCs do not start with a terminal window. To create a terminal window on a PC, click on the f icon at the left end of
the toolbar, and then click on the Terminal item in the menu of System Tools. Open a terminal window now. For the rest
of this tutorial will only be typing in one of these terminal windows.
Once you have created a terminal window, you will see a command line prompt indicating that Unix is ready to accept
your instructions. This prompt will usually have your username, computer name, and end with a "$", but may be
terminated by a "%". The prompt is generated by a program known as a shell. This is simply a program that accepts your
commands and gets UNIX to execute them.
Start Putty now. You will see a dialog window with the cursor flashing in the Host Name box. Now
enter the name of computer name you chose, including its domain. In our example, you would type:
pc17.cs.ucdavis.edu. Once you have entered the computer name, you make sure that the Connection Type is
ssh, and the Port is 22. If you wish, you can save this connection information for later use my entering a
descriptive name, e.g. CSIF or pc17, in the Saved Sessions box, and then clicking Save. Now click
Open
Since you will have never connected to this CSIF computer before, PuTTY will produce the PuTTY
Security Alert dialog box that asks if you trust this host. Click Yes.
Now enter your Kerebos username, and then your Kerebos password. You should now see a prompt in
the PuTTY window that reflects your username and the remote computer, e.g. [ssdavis@pc17 ~].
all the hostnames (computers) in the network, which ones are up and down, and the number of users for each host that is
up. Look through the list, and choose a computer that is up, and has few users on it. We will assume you chose pc27
for this example. We will walk through the steps of using ssh before having you actually issue the ssh command.
When specifying a computer name for ssh, you may omit the remote computers domain (cs.ucdavis.edu) if your
local computer is in its domain, i.e. in the CSIF, so in this example you could type: ssh pc27 rather than ssh
pc27.cs.ucdavis.edu.
If you have never connected to the computer before, ssh will ask if you are sure of the remote computer's
authenticity:
The authenticity of host 'pc27 (169.237.5.98)' can't be established.
RSA key fingerprint is a6:73:a3:d5:97:ae:e3:f5:65:8c:5b:a6:37:8c:bb:79.
Are you sure you want to continue connecting (yes/no)?
In such a case, just would type "yes".
Once the authenticity of the remote computer is established, ssh will prompt you for password on the remote
computer. Note since you have already logged into a CSIF computer to get to this point, ssh will not ask for your
username.
Now you are ready to make a real ssh connection.
Type: ssh computer_name, where computer_name is a pc computer that you chose from the ruptime list.
Once you have entered your password, please make sure that you are logged into a different computer from the
original CSIF you started with by looking at the prompt in the terminal window, e.g [ssdavis@pc27 ~]$. For the next
few exercises you will use this remote computer.
.
..
.DECkeymaprc
.FVWM2-errors
.SGIkeymaprc
.Xauthority
.addressbook
.addressbook.lu
.bash_history
.cshrc
.cshrc.COPY4U
.dt
.dtprofile
.emacs
.emacs~
.f
.forward
.history
.login
.login.COPY4U
.mailrc
.mh_profile
.msgsrc
.netscape
.newsrc
.oldnewsrc
.pine-debug1
.pine-debug2
.pine-debug3
.pine-debug4
.pinerc
.rhosts
.sh_history
.ssh2
.tin
.wm_style
.wmrc
.xmotd
.xsession-errors
Where did all these files come from? Note that all of them start with a period. UNIX hides system files that are normally
not needed by the user by starting them with a period. There are two unusual files listed, ., and ... These have
special meanings in path names. . stands for the current directory.
Now type cd . (with just one period after cd).
Now type pwd. You havent moved within the directory structure!
.. stands for the parent directory of the current directory. Now type cd .. (with two periods after cd).
Now type pwd. You should see /home.
Now return to your home directory by simply typing cd
Now type ls al The l option stands for long. The shell will display a line of information for each file. Here is an
excerpt from my home directory:
drwxr-xr-x
drwxr-xr-x
-rw-r--r--rw-------rw-r--r--rwxr--r--rw-r--r--rwx------rw-------rwx------
27 ssdavis
4185 root
1 ssdavis
1 ssdavis
1 ssdavis
1 ssdavis
1 ssdavis
1 ssdavis
1 ssdavis
1 ssdavis
users
users
users
users
users
users
users
users
users
bin
Links field (second from left): number of short cuts to this file from other directories.
Notice there were no pathnames after any of the ls commands. That means that you saw the contents of the current
working directory. If you do put a pathname afterwards, then you will see the contents of the directory identified by that
pathname. Now type ls /
In this example, the pathname you gave ls was the root directory (indicated by a sole backslash), which is the top
directory in the Unix file system. All the files you see listed there are subdirectories of the root. Notice the subdirectory
home. That is the subdirectory in which the home directories of everyone having an account are located.
..
second
third
2 ssdavis
2 ssdavis
users
users
4096 Jan
4096 Jan
7 22:29 second
7 22:29 third
~ssdavis/CSatHome.txt
myfile
Use ls to make sure that you were successful. You should see only myfile, and third listed.
Now copy this file down into the third directory by typing cp myfile third
You could check your work by cding into the third directory and then using ls, but there is simpler way. Just type ls
third to display the contents of the third directory. You should see only myfile listed.
The mv command has three syntaxes: 1) mv old_file_name new_file_name, to change the name of a file, 2) mv
{filename}+ directory_name, to move file(s) into a directory, and 3) mv old_directory_name new_directory_name to
change the name of a directory. You will try each one in order.
Now type mv myfile wombat to rename myfile to wombat.
Use ls to check your work. You should see only third and wombat listed.
Now type mv third/myfile . (note the period indicates the current directory) to move myfile to the current
directory.
Again use ls to check your work. You should now have myfile, third, and wombat in the current directory.
Now type mv third fourth, to rename the third directory to fourth.
Use ls to check your work. You should now see fourth, myfile, and wombat listed.
The syntax of the command to remove files is rm {file_name}+.
Now type rm myfile
Use ls check your work.
Your current directory, first, should now contain only one directory, fourth, and one file, wombat.
You can download WinSCP from http://winscp.net/eng/index.php. You can download s GUI version of sftp for
Macs by following UCD Resources->Software->File Transfer tabs within your MyUCDavis web page to get
Fugu for Macs.
The syntax of sftp is: sftp computer_name. As with ssh, you do not have to include the domain of the computer if you are
ftping from a computer in the same domain. You are now going to go through the process of getting your wombat file
from another computer.
Before continuing, type cd to get you in your home directory.
Now type sftp computer_name, where computer_name is some CSIF computer (remember ruptime?).
As in ssh, if you are trying to access a computer that is new to you, sftp will ask you to OK its authenticity; do so. You
will be asked for your username. In this case you can simply hit enter, because the username it has detected is proper for
the destination computer. If your account is under a different name, then you have to enter that name. Typically, many ftp
sites let you access them under the user name anonymous, using your e-mail address as the password. In the CSIF you
ftp also has a dir command which works like ls -l to show more
Now type pwd, and you will see that you are in your own home directory.
Now type cd first/fourth to move the remote ftp session into the fourth directory.
You can use lcd to change your local directory.
Now type lcd first to move to your first directory on the computer in front of you.
Now type lpwd to see where you are on the computer in front of you.
Now type ls to see the files available to you on the remote computer.
You should see snake and wombat listed.
The "get" command retrieves files from the remote computer. Now type get snake to retrieve snake into your first
directory.
If you had wanted to move multiple files you could use mget which has the syntax of mget {file_name}+.
If you had wanted to transfer a file from the local computer to the remote computer you would use put, or mput.
Now that you are done transfering files type bye to end the ftp session.
To see if snake is really in your first directory you can type ls first.
Now type handin cs30 tutorial to see that the files are indeed in that directory. You should see both snake and
wombat.
Text Editors
There are three text editors available: 1) vi, 2) emacs, and 3) joe
The first two each require some effort to master. See the references for more details. The last one, joe, is menu-driven and
fairly self explanatory, though much less powerful than the others.
To create a new file, or edit an existing one, just type the name of your editor followed by the name of the file, e.g. vi
myfile. You can also type any editor name without specifying a file, then save whatever you have done to a file later.
One feature of emacs which is expecially powerful is the ability to maintain multiple buffers of files. Each file that you
open is stored by emacs, so that you can switch among them, working on each one or comparing them without having to
open up another text editor to do so. In addition, you can run a shell from emacs, so that you can interact with the
computer without leaving the text editor environment. This is especially handy if, for example, you are trying to debug a
program. You can edit your program, then compile and run it to see if it works, all within emacs.
To remove a print job, the syntax is lprm job_number Notice you can get your job number from the lpq command.
Without the job number, you would remove only the job of yours that is currently active. To remove all your jobs, put a
dash in place of the job number, e.g. lprm The other print command that is useful for compressing two pages onto one has the syntax:
enscript [-2r] [-h] {file_name}+
As expected, the -h option is used to suppress printing of the header page. But more important, the option -2r says that you
want to rotate the paper sheet by 90 degrees, and print two pages onto this one sheet. This saves paper and lets you read
more of a long program at a glance.
10
The square brackets [] indicate that the options are optional! In other words, you don't have to type any options to
run the basic command. If you do use options, then you must select from a list that comes after what is shown
here.
name ... means that zero or more names of files may be entered here. The three dots indicate that the number of
names is variable. If you enter no name, then by default you'll get a listing of the current working directory.
The man page presentation is shown using more (see above, "Displaying Files"), so when you have read one full screen,
you hit the spacebar.
11