CS 124, Spring 2014
Pre-lab: Introduction to Linux
Welcome to CS 124, Introduction to Programming. In this course, you will learn how to write computer programs in the Java programming language. In the labs for this course, you will be using the Linux operating system. This "pre-lab" is a short introduction to Linux. You can read more about Linux at HWS at math.hws.edu/about_linux.
There is one short exercise for you to complete for this pre-lab. You will create a text file and copy it into a folder that you will use regularly for homework that you submit for this course. You should try to do that before you leave Gulick 208 today. I will give you a token few homework points for completing this assignment.
Getting Into and Out of Linux
Linux, Windows, and Mac OS are operating systems that provide your basic interface to the computer. The computers in Gulick 208 are usually running the Windows operating system, but they are also set up to run Linux instead. There are actually many versions of Linux. The one we are using is called "Linux Mint."
To get into Linux, restart the computer if it is running Windows, or start the computer if it is turned off. (To restart, hit Control-Alt-Delete to get to the login screen. Then, use the small "power button" menu on the bottom-right of the login screen and select Restart.) As the computer starts up, there is a point where you are given a choice between "Windows" and "Linux Mint". Press the down-arrow key once to select "Linux Mint", and press return. You have about 30 seconds to do this. After a short time, you will see a Linux login screen.
Log in using the Linux user name and password that were assigned to you. (Your Linux user name is the same as your user name for email and for the campus network, but the password is different.)
Note: When you are finished using Linux, you should always restart the computer so that it will boot back into Windows. You can do this by selecting the icon on the bottom left of the Linux applications menu, then selecting Restart in the dialog box that pops up. You do not have to wait around for the restart to complete.
You will see the following "Welcome Screen" the first time you log on to Linux. You will want to close it, but make sure to uncheck the box labeled "Show this dialog at startup" or you will have to close it every time you log in:
Click the "Menu" at the lower right corner of the screen to get to the Applications Menu, as shown at the right. This contains many programs that you can explore when you have the time. Now, click the third icon down on the left to open the "Cinnamon Settings" dialog so that you can change a few settings. I suggest the following: Go to the "Desktop" settings, check "Trash icon visible on desktop" and uncheck "Computer icon visible on desktop". Go to "Hot Corner" and uncheck "Hot corner enabled." But this is up to you.
More important, use the Application Menu to open a "Terminal" by clicking the fifth icon down from the top of the menu on the left. (Note: you can drag this icon into the panel, next to the word "Menu" as I did in the picture on the right to make it easier to open the Terminal in the future. You can also find Terminal in the Applications Menu under "Accessories".)
The Terminal is where you will do most of your work, at least for the first part of the course. The Terminal is a "command-line interface." You type commands to the computer, and the computer carries them out. As it executes the command, it might show output from the command in the Terminal. When the computer is ready to accept a command, it prints a prompt in the terminal.
Getting Started on the Command Line
You should be working in a Terminal. Here are a few commands you should use now. Type them exactly as shown, and press return after typing the command:
- ls -- This command lists the contents of the "current directory." Directory is another name for folder. When you are using the Terminal, you are always working inside a folder called the current directory. When the Terminal first opens, you are in your "home directory." This is the same folder that you will see if you double-click the "Home" icon on the desktop.
- mkdir cs124 -- This makes a new directory inside the current directory. The name of the new directory is "cs124." Note that when a command completes without error or output, you get no feedback except for the input prompt. You can store all of your work for this course in the cs124 directory. (This is not required, but my instructions for the labs will assume that you are doing so.) Try the "ls" command again, and you will see that the new directory exists.
- cd cs124 -- This means "change into the directory named cs124 that is in the current directory." You are now working in the directory cs124 instead of in your home directory. If you use the "ls" command now, nothing will be listed because there are no files in the current directory.
- mkdir lab0 -- Create another directory named lab0. Note that it is created in the current directory, that is, inside cs124.
- cd lab0 -- Change into the directory that you just made, so that you are now working in that directory.
- gedit test.txt -- This runs a program named gedit and tells it to edit a file named "test.txt" in the current directory. Since that file does not yet exist it will be created and you will see an empty window. (If you use gedit on a file that already exists, the file will be opened so that you can edit it.) Type some stuff in the window—anything at all—and then save the file and quit from gedit using commands in the "File" menu. Note that you should save the file into the lab0 directory. Note that you can't do anything in the Terminal until you quit from gedit.
- cd -- If you use cd with no directory name, it takes you back to your home directory. Use "ls" to verify that you are back home.
- passwd -- Use this command to change your Linux password to something that will be easier for you to remember. You will be asked to type your old password and then the new password twice. Press return after typing each password. The passwords will not be shown as you type them.
There are many more commands that you can use on the terminal. They will be introduced as they are needed. You can learn more in the "Command Line" section of the About Linux page, http://math.hws.edu/aboutlinux/commandline.html
Setting Up and Using Gedit
You will use gedit for Java programming, and you should make some changes to the gedit configuration to make it more suitable for writing programs. To do this, start up gedit again, by giving the command gedit in a terminal. Then, select the "Preferences" command from the "Edit" menu in the gedit menu. Change the settings in the "View" pane and in the "Editor" pane as follows:
That is, you want to check "Display Line Numbers", uncheck "Enable Text Wrapping", check "Highlight Matching Brackets", set "Tab Width" to 4, check "Insert Spaces Instead of Tabs", and check "Enable Automatic Indentation".
(The reasons for all this are that line breaks and indentation are important in programming. You don't want the editor to insert extra line breaks, and you will need to see line numbers. The rest of the changes will help you keep the indentation of the program regular. Checking "Highlight Matching Brackets" is optional but can be useful.)
Turning in Your Work for this Pre-lab
Quit from gedit so that you can work in the terminal again.
I would like you to copy the lab0 directory that you made to a location where I will be able to access it, since I don't have easy access to the files in your home directory. You will submit your work by copying it into a directory named /classes/cs124/zz9999, except that instead of typing "zz9999" you should type your own user name. This long name is a "full path name" that tells the computer exactly where to find something, no matter what current directory you are working in. The full path name /classes/cs124/zz9999 tells the computer "staring from the top of the file system (/), go into the directory named classes, then go into the directory named cs124, and find the file or directory named zz9999. (In this case it's a directory.) The full path name for your home directory is something like /home/zz9999.
Use the following commands in a Terminal to submit your work:
- cd cs124 -- change into your cs124 directory. This assumes that you were in your home directory to begin with. Remember that you can move into your home directory by using cd with no directory name.
- cp -r lab0 /classes/cs124/homework/zz9999 -- where you should type your own user name instead of zz9999; copies your lab0 directory into your homework directory. The command cp is used to copy files. The "-r" in the command is a "command option" for the cp command; it means to copy an entire directory, including its contents. Since the directory /classes/homework/zz9999 already exists, a copy of lab0 is placed inside that directory.
- ls /classes/cs124/homework/zz9999 -- again typing your user name instead of zz9999; shows you the content of the directory /classes/homework/zz9999. You should see lab0 listed. There should be a text file inside the lab0 folder. See if you can figure out how to check that it's there!
In future labs, you will create lab directories and submit them for grading in much the same way.
If you finish all of this before the class period ends, feel free to explore some of the programs in the application menu. One thing that you might do is start up the Firefox web browser and add the course web page, http://math.hws.edu/eck/cs124, to the Bookmarks.
Working Outside of Lab
This section is for your future reference. You will need to do a lot of programming work outside of lab. You have many options for working on Java programs on your own. Here are some things that you can try.
- You can work on the computers in the Math/CS lab, Lansing 310. These computers are always running Linux and do not have to be rebooted; otherwise, they work the same as the computers in the Gulick 208 lab. Furthermore, there will be computer science TAs in Lansing 310 every Sunday through Thrusday, 7:00 to 10:00 PM.
- You can usually work in Gulick 208 in the evening and on weekends, when it is not being used for classes.
- You can write, compile, and run Java programs on your own computer, if the JDK (Java Development Kit) has been installed. If you work on your own computer, you will need to copy your work onto the Math/CS Department's file server. One way to do that is with a program that supports "sftp"; see http://math.hws.edu/about_linux/sftp.html.
- If your computer uses Mac OS or Linux, you can use ssh to connect to the Math/CS lab computers and work on them remotely. See http://math.hws.edu/about_linux/ssh.html for information.
- You can log onto one of the Mac OS computers in the library or in a computer lab (using your Windows/email password), and then use ssh to work remotely on one of the lab computers.
- You can use VNC on your own computer to work remotely on Math/CS computers. See http://math.hws.edu/about_linux/vnc.html for details. However, VNC can be slow and buggy. It is really not a great way to connect.