Using Linux

The goal for this week's lab is to learn about the computer environment and some of the applications you'll use in your CSCI 201 labs. You don't need to have a broad knowledge of computers to write simple programs, but there are a few skills you do need. Here's what we'll cover:

  1. Controlling applications in a windowed environment
  2. Using files and directories
  3. Running Java in a command session

The Desktop

In this lab we assume you are using the network Linux workstations managed by the Department of Computer Science at UNCA. We also assume you are viewing this page in a browser window. This means that you have successfully found a computer, powered it up, logged on, started an Internet browser and loaded this page. If that is not the case, please refer to First log in to Linux at to get started in the proper configuration.

Your computer should display a desktop roughly similar to the screen capture shown below.

Hey. This doesn't look that different from Windows does it? In fact, the Linux and Windows user interfaces are derived from a common standard defined about a decade ago. The initial display may be slightly different on other versions of Linux. The Computer Science machines use the GNOME desktop. If you want some very detailed information on Gnome consult a recent copy of the GNOME Desktop User Guide.

Controlling Applications in a windowed environment

The Panel

At the top of the screen is the Panel. It is very similar to the Windows "Taskbar". On the left side of the panel is a row of "launcher icons".
The leftmost button, the one that looks like a red hat, is the main menu button. It is similar to the Windows "Start" button.

Select the Main Menu button with the left mouse button, and you will see a menu that allows you to run applications by selecting their icons with your mouse.

Move your mouse so that the cursor moves up and down the selection of items on the menu. Notice that when you move the cursor to a menu selection with a right arrow, a sub-menu is displayed showing you more even more selections. Navigate through the menu to start the text editor. Start in the upper left corner of the screen. You'll find the text editor by going through the menu selections Applications → Accessories → Text Editor.
GNOME menu select for gedit

The window and its controls

The GNOME text editor is also known as gedit. Observe its window.
gedit starting
For you Windows users, it's deja-vu all over again. At the top of the window is the titlebar which shows the name of the application that is running. On the right side of the title bar are three control elements: _OX. Directly below the titlebar is the menubar, a row of words such as File and Edit. If you press a word on the menu bar, you will be rewarded with a pulldown menu which can be used to direct the actions of the applications. Below the menu bar, you'll often find a toolbar containing many icons. These icons can be used to perform useful actions, such as opening and saving files.

Let's return to those three buttons on the right end of the titlebar. The rightmost button, close button, is the close windows button. This button terminates the running application and closes its window. The middle button, maximize button, is the maximize button. It expands the window to the size of the full screen. This is rarely anything you'll want to do. Only the leftmost or minimize button, minimize button, remains. This control suspends the application. There is a taskbar at the bottom of the screen that can be used to revive suspended applications.
Gnome taskbar

Moving and resizing the window

If you press the leftmost mouse button within the titlebar of a window, you can drag the application to different locations within the screen.

If you move the mouse to the edges or corners of a windows, the cursor will become a two-headed arrow. If you then press and hold down the leftmost mouse button, you can change the size of a window.

Managing workspaces

You may have noticed a rectangle containing four little boxes in the lower right corner of the panel. This is the workspace switcher.

GNOME supports four different workspaces that share a panel. Each workspace can display its own set of applications. Each box of the switcher is a miniture representation of a workspace. Clicking within the switcher "opens" other workspaces. To move an application from one workspace to another, simply drag it within the switcher. You can also right-click on the maximize button, maximize button, and choose a new workspace.

Trying it out

There's no point in giving more explanation. It's time for you to create a text editor window. Now move, resize, minimize, and unminimize it. Now drag the text editor window onto a different workspace than your browser window.

If you have any trouble, get the attention of your lab instructor or the person in the adjoining chair.

Show your scattered windows to the lab instructor.

Files, directories, and shells

The basics -- what you should already know

If you've taken CSCI 107, you should have learned about directories and files in Lab 2 of CSCI 107. If this is your first exposure to this concept, settle in for a few minutes of serious study. A file is a collection of data, generally formatted for use by a specific application, such as a database or spreadsheet. A directory is a collection of files and other subdirectories. You can think of files and directories as analogous to the structure of a file cabinet. The file corresponds to the documents you store in your file cabinet and the directories correspond to the file folders---they provide a way of grouping and organizing documents. Subdirectories are nested file folders---a folder inside of another folder.

File names

Files and directories have names. In both the Linix and Windows worlds, these names are series of directory names separated by slashes: forward slashes, /, in Linix; and backward slashes, \, in Windows. (By the way, it was Unix, the precursor of Linux, that first used the slash.) Here are example file names in both Unix and Windows:

Notice, that both of the above file names start with a slash, which means that both emanate from a special root directory. These are called absolute file names. Windows has the additional complexity that absolute file names may start with a drive letter, as in A:/autoexec.bat, to specify the drive on which the file is located. You may also notice that in our example the Windows file name contained spaces while the Unix file name did not. Although you can put a space in a Unix file name, it is not recommended and may offend true Unix gurus. Even worse, it sometimes confuses the Java system, on both Windows and Unix. For this reason, we suggest you avoid spaces in CSCI 201 file names no matter what computer you are using.

Notice that both of our example names end with ".java". In both Unix and Windows it is common for file names to end with a period followed by an extension, "java" is our examples. The extension generally identifies the type of the file. Remember that a file is a collection of data formatted for a specific application; the type of the file indicates the application. You'll be generating a lot of files with the extensions "java" and "class" this term; I'll bet you can guess the application.

Both Unix and Windows support relative file names. These names do not begin with a slash and are considered to emanate from the current directory. So, if your current directory is /usr/bin and you speak of the file X11/mwm, you are really talking about /usr/bin/X11/mwm.

Graphical display of files

Most computer users, especially those of the Macintosh sect, use directories and files with absolutely no idea of how a slash is used in a file names. They use file explorers. Many, but not all, versions of Linux have a graphical file interface called Nautilus. Your desktop should contain an icon labeled something like yourid's home that can be used to explore your Linux files.

However, we really don't do that many fancy things with files in CSCI 201, so we're going to just use the old-fashion Unix file commands. This will allow you to access your files through a network connection and, after all, it's what all the true Linux gurus do.

The shell

All operating systems have a command line processor in which you can type commands. In Windows this is often called the DOS prompt, even in Windows operating systems that aren't based on pre-historic DOS.

In Linux, this program is called the shell. The first popular Unix shell was named the Bourne shell, after its creator Steve Bourne. Today the most popular Unix shell is a revision of the Bourne shell called bash, an acronym for the Bourne again shell.

There are a couple of ways to start bash within its own terminal window. You can use main menu selections, Applications → Accessories → Terminal. However, the fastest way of obtaining a terminal window it to right-click on any unoccupied space of the desktop and bring up a small menu from which you can choose Open Terminal.
desktop menu

When bash is running, you'll type commands to its prompt. On most Linux systems the prompt is rather verbose: [yourid@yourmach currentdir], where yourid is your Unix user name, yourmach is the name of the Linux computer you are using, and currentdir is the name of your current directory.

Useful Linux commands

Below is a summary of the commands that you'll find useful in this course. Take a look at these commands. Do not use them, you'll be asked to use several of them in the assignment section below.

pwd Print Working Directory:
Prints the full pathname of your current directory.
cd directory Change Directory:
Changes your current directory
cd Without an argument, cd changes your current directory to your home directory.
ls directory List:
Lists the contents of a directory or sometimes just lists a file.
ls Without an argument, ls lists the contents of the current directory.
ls -l ... With the -l option, ls provides a more detailed directory listing.
ls -a ... With the -a option, ls lists "hidden" files, that is, files whose name starts with a period. By convention, most user "configuration" files start a "hidden."
ls -R ... With the -R option, ls lists a directory and all its subdirectories.
mkdir directory Make Directory:
Creates a directory.
rmdir directory Remove Directory:
Deletes an empty directory.
rm file Remove:
Deletes a file.
cp oldfile newfile Copy:
Creates a new file that is a copy of an existing file.
more file More:
Displays a file one screenful at a time.

To learn more about working with Unix files and directories, take a look at the Unix tutorials of the Idaho State University Computer Center.

Your account has been created in such a way that, in general, only you and the CSCI 201 instructors can access files within your csci directory. If you want to learn more about Linux file permissions (and you should), take some time to read our Unix File Permissions tutorial.

Trying it out

Start up a Linux terminal session as explained earlier in this section. Now you can type raw Unix commands into your terminal session.

First type the command pwd. This will print the name of your current or working directory. The command should respond with something similar to /home/yourid where yourid is your login name.

[yourid@yourmach ~] pwd

You can list the contents of the current directory with the ls command. If this is the first time you've used your CSCI account, you'll be surprised to find that there is already a subdirectory in your home directory named csci. Try the bare ls command along with the ls -l and ls -a commands. The options -a and -l must be separated from the program name ls with at least one space. We list the commands, but not their output below.

[yourid@yourmach currentdir] ls
[yourid@yourmach currentdir] ls -a
[yourid@yourmach currentdir] ls -l

The bare ls command lists very few files and directories, probably only csci. Adding the -a, or all, option causes several hidden control files to be listed. Adding the -l, or long, option gives more information about your file. For example, you see the owner, size, creation date, and, most importantly, the permissions of the files.

Finally create a directory csci/201. Hopefully you read this section carefully and know how to create this directory. If you don't; reread the section, don't ask the instructor. (Hint: mkdir is an abbreviation for "make directory.")

You may have noticed that there was no confirmation that the directory was actually created. Linux is like that. It only speaks when something goes wrong. Repeat the command to create csci/201 and notice that Linux now complains. If you want to confirm that a file or directory exists, you should use the ls command.

Show your terminal session, with the newly created csci/201 directory, to the lab instructor.

Running Java

It's possible to use a text editor, such as Linux's gedit or Window's notepad, to create files containing Java programs and to then use the command line to execute them. We're not going to do that in CSCI 201, but we do want to show you how to use the command line to determine which version of Java you are using. It's simple. Just type the command "java -version". You should see something similar to the following output even if you are running Windows at home.

[yourid@yourmach currentdir] java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

Pay attention to the line of output that gives the version, in this case 1.6.0_07. If your version is not some flavor of 1.5 or 1.6 you need an updated Java SE Development Kit (JDK).

By the way, if you have installed the JDK on your home Windows computer and get the following message you need to read Sun's instructions for setting your PATH in Windows.

C:\>java -version
'java' is not recognized as an internal or external command,
operable program or batch file.

Saving a file

Go to the text editor and write a couple of sentences about your experience with computers and, if appropriate, programming. Save this information within the file csci/201/lifestory.txt, that is, as the file lifestory.txt within your csci/201.

Have your lab instructor verify that your file has been stored in the correct location.

One last task

Changing your password

Return to the Linux terminal and execute the kpasswd command to change your password to something you can remember. Using the same password that you use for email at UNCA might be a good idea.

[yourid@yourmach currentdir] kpasswd
Password for yourid@CS.UNCA.EDU: [old password will not be echoed as you type it]
Enter new password: [new password will not be echoed as you type it]
Enter it again: [new password will not be echoed as you type it]
Password changed.

Be sure to remember your username and password. Your lab instructor cannot reset your password during class. The best he/she can do is send you to find the system administrator.