CSCI 201 -- Using Linux

The goal for this week's lab is to learn about the computer environment and 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. Submitting your homeworks
  4. Transfering files with secure FTP
  5. 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. For a little more information on the Graphical Desktop consult Chapter 2 of the Red Hat Linux Getting Started Guide. For a lot more information on Gnome consult a recent copy of the GNOME Desktop User Guide.

Controlling Applications in a windowed environment

The Panel

At the bottom 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. You'll find it by going through the menu selections Main Menu → 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.
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.

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 middle 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, Main Menu → System Tools → Terminal. Or you can right-click on any unoccupied space of the desktop and bring up a small menu from which you can choose New 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, 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 -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 this more comprehensive Working with Files and Directories tutorial created by the Idaho State University Computer Center.

Linux file security

Usually Linux is a multi-user operating system where the directories of several users are stored. You can control who may view and modify your files and directories by setting Unix file permissions.

Permissions are divided into three types:

r read Allows reading the contents of a file or listing the files of a directory.
w write Allows modifying the contents of a file or creating and deleting the files of a directory.
x execute Allows a file to be executed. Allows the files and subdirectories of a directory to be accessed.

A directory with read permission turned off but execute permission turned on is similar to a town where everyone has an unlisted phone number. You can't list the numbers; but, if you know one, you can call it.

Each file is "owned" by the person who created it. Files can also be associated with user groups created by the system administrator. For example, all CSCI 201 students could be placed in a group called csci201. Each of the three file permissions can be turned on and off for three different classes of users:

u user The owner of the file
g group Members of the group associated with the file
o other All others

File permissions are set or changed with the chmod command, a rather difficult tool to master. To set file permissions, you use the letters 'u', 'g', or 'o' to specify to whom the permissions apply; then your use the plus sign to add a permission and the minus sign to remove a permission; and finally you use some of the letters 'r', 'w', and 'x' to specify the type of permissions to be added, deleted, or set.

That's all pretty difficult to follow. Let's look at some examples:

chmod g+rw groupfile Allows the file groupfile to be read and written by group members.
chmod go-rwx secretdir Makes the directory secretdir unreadable and unwriteable by anyone other than its owner.
chmod ugo-w readonlyfile Makes the file readonlyfile unwritable by anyone.
chmod 711 dropoffdir A command you can use after you learn octal and become a Linux geek.

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 currentdir] 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 and protect it so that only you can read it. Hopefully you read this section carefully and know how to create and protect this directory. If you don't; reread the section, don't ask the instructor.

By the way, there are special system programs that allow Computer Science faculty to puruse your csci directory even though it is read protected.

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.

Creating a Java file

The file to create

Usually in CSCI 201 you will create your programs using NetBeans; however, right now we want you to do things the old-fashioned way so that you'll have an appreciation for way the NetBeans uses files and directories. In this section you are going to create a directory called csci/201/lab0src containing a Java file called

Creating the file

Hopefully, you still have at least one of those gedit applications running. If not, you need to start one. Now use your mouse to select and copy the following Java code from your web browser. You can perform the copy by typing Cntl-C or by using the menu selections Edit → Copy.

//  Author:     Your name goes here
//  Assignment: Intro lab

public class cruelworld
   public static void main (String[] args)
      System.out.println ("Goodbye Cruel World!");

Now paste the copied code into the text editor.
Code pasted into gedit

The next step is the actual saving of the file. This is a little tricky because you must create the lab0src directory while saving the file. After pressing gedit's Save button, you'll see a pop-up windows labelled Save as.... Use your mouse to navigate to your csci/201 folder. Now press the New Folder button; and you'll see a new dialog window in which you can type lab0src, the name of your new folder.
File browse in gedit
Press Create to really create lab0src. Then you'll need to nagivate into your newly created csci/201/lab0src directory. Next return to the Save as... and type your file name in the Selection text box.
File browse in gedit

Show your instructor the result of typing the following command, which should display your new file.

[yourid@yourmach currentdir] more ~/csci/201/lab0src/

Running Java

Getting the right stuff

The CSCI 201 textbook is based on Java version 1.5. Java is distributed in two flavors. The JRE, or Java Runtime Environment, contains the JVM, or Java Virtual Machine, which is able to run Java applications within a browsers. Although Microsoft stopped distributing their "version" of the JRE to settle a court suit, most computer manufacturers include Sun Microsystems's JRE in their system. However, the JRE isn't enough for CSCI 201. You need the JDK, Java Development Kit. This can be downloaded from the Sun Developer Network Site.

When using a computer for Java development, the first thing you should do is check which version of Java is being run. Do this by typing 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.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

If your version is not some flavor of 1.5 you need an updated Java Development Kit (JDK) install.

By the way, if you have installed the Java SDK 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.

Compiling your Java program

Now let's change our current directory to csci/201/lab0src, the directory where our Java program is stored, and use the command javac to compile the program.

[yourid@yourmach currentdir] cd ~/csci/201/lab0src
[yourid@yourmach currentdir] javac

The Java compiler, javac, translates your program into bytecode, a string of numbers understood by the Java Virtual Machine. If you now type the ls command, you should see another file called cruelworld.class that was created by the compiler and contains your bytecode.

Running your Java program

To run your program simple type the command "java cruelworld". You should be rewarded with the output of your work.

Show your instructor the output of your Java program.

Transferring files

Turning in assignments

After you complete a CSCI 201 assignment you must store it in a precise directory and file specified in the assignment handout. Only assignments stored in the appropriate file and directory will be graded. You must learn how to reliably transfer your files. No assignment will be graded unless it is stored in the appropriate location, and no assignments will be accepted by email.

The Department of Computer Science uses a secure file transmission protocol called SSH FTP, or Secure Shell File Transfer Protocol, for downloading files onto its computers. If you work at a windows platform, you will need to obtain a copy of a SSH FTP client program to transfer files to the 201 drop-off directory. We suggest the Windows users obtain a copy of WinSCP for this purpose. WinSCP should also be installed in the Windows based labs at UNCA.

Information needed for the transfer

To transfer a file you need to know three pieces of information:

  1. The name of the local directory containing the file. In our example, this is csci/201/lab0src.
  2. The name of the remote computer to which you are going to transfer the file. In CSCI 201 that will be
  3. The name of the remote directory to which you will transfer the file. We'll use csci/201/lab0dst today.
  4. The names of the files to be transfered. Of course, that is

Using sftp on Linux

Yes, it is rather silly to use a remote file transfer program to transfer a file from one directory to another on the same computer. But, that's what we're going to do today, just to make sure you have used as least one version of SSH FTP. The one we'll use is sftp, the Linux secure FTP program.

Start by going back to your terminal session window and type the command "sftp". You will be asked to accept an RSA fingerprint whenever your connect to a computer for the first time with sftp. The fingerprint is a security measure designed to prevent spoofing. You should enter "yes" to accept the fingerprint.

[yourid@yourmach currentdir] sftp
Connecting to
The authenticity of host ' (' can't be established.
RSA key fingerprint is c5:a5:92:94:6c:e1:9b:7d:cb:4d:a1:6e:24:00:45:37.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (RSA) to the list of known hosts.

Next you will be asked to type your password. Your password will not be echoed as you type it, and it will be transmitted using encryption to the server.'s password:Type your password here

Now it's time to make sure that sftp is connected to the correct local directory, in our case csci/201/lab0src. Note that in our case we are actually specifying /home/yourid/csci/201/lab0src just in case you weren't connected to your home directory when you began using sftp. Follow the lcd with an lls to list your local directory, just to make sure.

sftp> lcd /home/yourid/csci/201/lab0src
sftp> lls

Your remote directory is csci/201/lab0dst, but that directory hasn't been created. Use the sftp command mkdir to create the directory and then connect to your remote directory. Keep in mind that you have both a local and remote directory.

sftp> mkdir csci/201/lab0dst
sftp> cd csci/201/lab0dst

The file to transfer is At last you can use the put command to send the file and then quit the session.

sftp> put                               100%  218     1.4KB/s   00:00
sftp> quit

Show your instructor the result of typing the following command, which should display your new file.

[yourid@yourmach currentdir] cat ~/csci/201/lab0dst/

One last task

Changing your password

Return to the Linux terminal and execute the yppasswd command to change your password to something you can remember. By the way the 'yp' abbreviated "Yellow Pages" before British Telecomm threatened to sue Sun Microsystems. Now 'yp' is an abbreviation for "Network Information Services".

[yourid@yourmach currentdir] yppasswd

Log Out

Finally, you should log out. You can do this by typing the familiar Ctrl-Alt-Del, the well-known Secure Attention Sequence of Windows, and then selecting the logout option. You can also go through the main menu. After you press the hat, you'll see the Log Off at the bottom of the menu.