Espresso: A Concentrated Introduction to Java


An Introduction to Unix (in MathLAN)

Summary: We introduce (or re-introduce) the Unix operating system, particularly the key features necessary to compile and use Java in the Grinnell College Mathematics Local Area Network (MathLAN).

Prerequisites: None.

Disclaimer: Although I use the term Unix throughout this document, the ideas apply equally well to Linux, the variant of Unix we use in MathLAN.

Contents:

Operating Systems and User Interfaces

One of the central pieces of any computer is the operating system. The operating system typically controls the programs that runs on the computer, manages the disks and other devices on the computer, and generally shields the user from the inner workings of the computer.

Most computers provide some form (or forms) of user interface that permits people to give commands to the computer (e.g., start a program, rename a file, determine who else is using the computer). The user interface communicates these commands to the operating system, which then performs the commands (or extracts information that the user interface needs). Although many people consider the user interface part of the operating system, it is really an add-on to the operating system.

There are two basic kinds of user interfaces: graphical user interfaces, in which you interact with the computer through icons, menus, and such, and textual user interfaces, in which you interact with the computer by typing commands in a terminal window.

Although you can (and will) perform many actions on our Unix systems through the graphical user interface, there are many things that I would prefer that you do through the textual user interface, and some that you must do through the textual user interface, at least in this class.

Starting the Terminal Window

You can create a terminal window on our systems by clicking the little picture of a computer screen that appears in the command bar at the bottom of the screen. When you open a terminal window, you should see a prompt of some form (usually a percent sign or a greater-than sign).

Once the terminal window is open, you can type a variety of commands, which we will soon discuss. The simplest command is to type the name of a program, along with any information the program needs to run. For example, to run the Java compiler on the file Hello.java, we would write

% javac Hello.java

Similarly, to list all the examples in the examples directory for this class, we would type

% ls /home/rebelsky/Web/Courses/CS152/2006S/Examples/

Working Directory

Since life tends to become complicated if you have to put all of your files in one place, Unix permits you to create a hierarchial set of directories (file folders). For example, I have a directory for each class I teach and within that directory I have other directories (subdirectories) for homework, readings, outlines, and so on and so forth. Unix shows directory hierarchies by separating each directory with a slash.

When you are working in the terminal window, Unix has a notion of a present working directory. Commands that affect files use the files in the present working directory by default.

Users also have a home directory (the starting point of their explorations). In the MathLAN, this directory is /home/yourusername. You can refer to files with their short name (relative to the present working directory) or with a full name (starting with /home/yourusername or whatever is appropriate).

Important Commands

pwd
Give the name of the present working direcotry
ls
List all the files and directories in the present working directory.
ls directory
List all the files and directories in the specified directory.
less file
Look at the contents of a file. The space bar pages down, the b key pages up, and the q key quits. The slash key lets you search for a particular sequence of characters.
cd directory
Change the working directory to the specified directory. For subdirectories, you need only give the name of the subdirectory and not the full path.
cd ..
Change the working directory to the directory "above" the current directory.
mkdir directory
Create a new directory.
chmod options file
Set permissions on a file
chmod a+r file
Make a file readable by everyone (all add read).
chmod go-r file
Make a file unreadable by others (group/other subtract read).
chmod a+x directory
Allow others to access files in the specified directory, provided those files are readable.
chmod a+r directory
Allow others to see what files are in the specified directory.
cp sourcefile target
Make a copy of the named file.
cp filename newfilename
Make a copy of the named file.
cp filename directory
Make a copy of the named file in the specified directory.
mv filename newfilename
Rename the file.
mv filename directory
Move the named file to the specified directory.
man command
Get more information on the specified command.

Aliases

Sometimes commands are somewhat unwieldy to type. Unix permits us to add aliases that simplify typing. For example, suppose you regularly run the program /opt/jdk1.5.0/bin/javac, which is clearly a lot of stuff to type. You can enter the command

alias jc="/opt/jdk1.5.0/bin/javac"

From now on, any time you type jc, the terminal interprets it as the longer form.

You can put aliases in a file called /home/yourusername/.bashrc and the computer will remember them more-or-less permanently.

Editing

You now know how to create directories, to change permissions, to determine and change your working directory, and other administrative tasks. However, you do not yet know how to create and change files. We typically use a text editor for making and editing files. Unix provides a wide variety of text editors.

For our work, we will focus on gedit, a simple text editor. Those of you who have used an editor in the past should find it fairly straightforward. You will typically start gedit by typing

gedit filename

History

Tuesday, 25 January 2005 [Samuel A. Rebelsky]

Wednesday, 26 January 2005 [Samuel A. Rebelsky]

Monday, 29 August 2005 [Samuel A. Rebelsky]

Tuesday, 24 January 2006 [Samuel A. Rebelsky]


This page was generated by Siteweaver on Thu Mar 30 15:24:33 2006.
The source to the page was last modified on Tue Jan 24 09:20:04 2006.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Espresso/Readings/unix.html.

You may wish to validate this page's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky
rebelsky@grinnell.edu