Welcome to CS 12
Welcome to CS 12 labs. In this course, all programming will be done
under the Linux operating system, using standard programming tools for
that environment. Linux is a free operating system, available for all to
download (RH)
(Mandrake)
and use with no cost. Linux itself is about a decade old, but
in conjunction with a set of free utilities from the GNU project, behaves like a member of the UNIX
family of operating systems. UNIX has been the standard for research
institutions and the computer industry in general for decades. As
a matter of pride it is expected that you, as a Computer Science
student, will learn to use it. To help you toward this end, there
will be no usage of Windows during lab sections for CS12, nor
will any assistance be given to students wanting information on
moving/recompiling their assignments completed originally under
Windows. It is very
much in your best interest to get used to Linux as early as possible,
since it will be your primary tool for Computer Science for the rest
of your term here at UCR. Tutorials on Linux are available all over
the Internet, Google for "Linux tutorial"
and find one that suits you,
or just try This one.
In this lab, we will be doing three things:
- Handing out class accounts
- Getting a quick introduction to Linux
- Learning to use the CS Department turn-in system if you haven't already
Class Accounts
Temporary accounts are available for the duration of this course. In
order to receive one, you must provide photo ID to your TA. If you
have come to class unprepared and do not have photo ID, check with
your TA about how to proceed.
Once you have your account, return to your seat. If you have already
booted Windows, shut it down. When the Operating System choice screen
pops up again, choose the Linux option. After a few seconds, the
computer will ask you for your login information (user-name and
password.) Enter your new login for CS 12, and the appropriate
password. If you typed everything in correctly, you will be logged
into the Linux system.
Introduction to Linux
Linux has a Graphical User Interface much like Windows, but also has
an extremely powerful and all-encompassing command line interface that
allows you to interact more quickly and efficiently with the system.
To access this interface, click on the icon that looks like a black
computer monitor. This will pop up a window known as a "Terminal."
Inside your terminal window is where you enter your commands.
Basic Commands
- ls - list the contents of your current directory. For
those of you that have used the MS-DOS prompt, this is similar to
dir under MS-DOS/Windows.
- cd a - move into the directory a
- cp a b - copy file a to file b
- mv a b - move file a to b, removing
the original
- rm a - delete file a
- mkdir a - create a directory called a
- rmdir a - remove empty directory called a
- man command - display online help on command
- man -k word - search for help on word
There are literally hundreds of additional commands commonly
available, as well as a large number of options available for the
commands presented here. It is highly recommended that you
take some time to experiment with these commands, read some
documentation, and get to know your environment. With more than 25
years of history, nearly everything you might want to do has been done
and automated by some other developer and included in the plethora of
UNIX commands. Learning as many as you can will make your life later
on easier and easier. Start early.
Editing Files
There are many many options for editing text files under Linux. The
two most common are emacs and vi. Emacs is
somewhat easier for beginners, so we will focus on using emacs
in this course. We recommend that you experiment with other editors
to find the one that suits you best.
To invoke emacs, simply type emacs in a terminal window and
press Enter. Examine the menus on your own. If you have any
questions, ask your TA or search for help on Google.
Sending/Receiving Email
There are a vast number of options for reading your email under Linux,
ranging in features and complexity from Evolution (a program that
presents an interface similar to that of many common Windows email
programs) to "mail" (the offspring of one of the first email clients.)
We will focus on using pine, a common UNIX mail reader. To invoke
it, type "pine" on the command line (in a terminal window). If you
are running pine for the first time, hit "Enter" to inform the makers
of pine that you are using it (so they can estimate the number of
users).
Play with pine on your own, and ask questions if you have any. Try
sending yourself an email message, and make sure that you can read it.
Turn-in
7 points possible
We want to ensure that everyone understands how to use the turn-in
system, and that everyone has at least experimented with the basic
Linux commands presented here. Follow these directions to prove that
you understand both systems:
- Create a new directory, possibly called "lab1"
- Change into that directory
- Open a new file in Emacs called "lab1.txt."
- Add your name, the date, and your cs12 username to the top of your file.
- In a new terminal window, perform the following operations:
- Create a new directory called "lab1testdir"
- Change into that directory
- Launch emacs, save a new file called "testfile"
- Close emacs
- Make a copy of "testfile" called "copyfile"
- Move "copyfile" to "movefile"
- Delete "testfile"
- Delete "movefile"
- Change into your home directory (either "cd .." or just "cd")
- Remove the directory "lab1testdir"
As you go, copy the contents of your terminal window into your
original Emacs window "lab1.txt". (Note: To copy and paste under Linux,
simply highlight what you want to copy, and then hit the middle mouse
button to paste.) When you are done, save that file
and close Emacs.
Open a web-browser. Go to the CS department secure server Follow the
directions there to turn the directory that contains "lab1.txt".
Miscellaneous Tasks
1.4 points possible
When you are all finished, explore your Linux environment, the history
of Linux / UNIX, or other related things online. Attendance for the
full lab period is mandatory. Try working on some of the following
short tasks. To receive credit, add these to the top of your
"lab1.txt" file and turn it in again. Each task is worth 0.2 points,
out of 10 possible.
- Learn three of the most common Emacs keyboard shortcuts: Save,
Quit, and Save As. Write down instructions for using them.
- Find a command line program that will let you count the number of
words in a text file. Write down what that program is and how to use it.
- Find a fast way of viewing the contents of a text file from the
terminal, without opening an editor (that is, other than Emacs or vi
or anything that will let you make changes to the file.)
- In one or two sentences, describe the program "diff." Use the man
page or the Internet to find information about it. Try it out.
- What does the command "echo Hello there! > newfile.txt" do?
Bonus
- In Emacs, write a C++ program that prints out "Hello World!".
Turn this in as "lab1.cc".
- What command can you use to compile "lab1.cc"?
If you finish with all of this, you can either browse around for
information on Linux / UNIX, more shell commands, or more information
on Emacs or any of the other text editors available under Linux.
Lab Grading
Attendance - 2 points
Terminal session turned in - 7 points
Misc. Tasks - 1 point
Extra credit - .4 points
Total: 10.4/10