CSC15 Assignment 1: Unix

Due Monday, 2/5/2001

This lab is intended for you to:
  1. Learn basic Unix "survival skills"
  2. Set up the environment you will use for the rest of the semester
  3. Learn how to enter and compile a basic C++ program using the GNU C++ compiler
  4. Learn how to enter and compile a C++ program that uses the Qt graphical library
  5. Take a glimpse at the joys and pains of programming by modifying some simple program lines.

Unix is an advanced operating system that predates Microsoft windows by many years. It is used by scientists, software developers, and is the backbone of many internet resources. It is not as easy to use as Microsoft Windows but is more powerful, especially when it comes to computer networking. The version of Unix we will be using this semester is "Solaris", which runs on Sun workstations in Adams 204.

Unix has improved in usability in recent years. In particular, there are now "graphical user interfaces" available. When you log into your account, you'll see a graphical desktop called "CDE" - for "common desktop environment". This environment behaves somewhat differently from that of Windows 98 - be sure you follow the demonstration and note its peculiarities. You'll be required to familiarize yourself with this environment after some initial instruction.

To log in to the Solaris Workstations, first select "options" on the log in screen, then select "session" and then "common desktop environment(CDE)". Then type in your username. Your username should be the first character of your first name plus up to 5 characters of your last name, plus a number (usually 1). For example, if you are Jane Smith your username would probably be jsmith1. But if there's another Jane Smith on campus you might be jsmith2. Your password is initially set to your social security number.

When you first log on, you'll see a number of windows come up. The one that's important is called "file manager". You can quit/destroy the other ones. The file manager displays files in your directory.

The unix file system is similar to the file system of DOS and Windows 98, but there are some important differences. First of all, there is no "A" drive or "C" drive. Instead, there is a "root" directory called "/" and all directories are arranged in a hierarchy. Your "home" directory is displayed in the file manager - it should be something like /home/jsmith. Note that the "/" is in the opposite direction of MS Windows directory names, which uses "\" just to be original.

Here's a basic tutorial. If at anytime you're stuck and couldn't figure out what to do, start over by opening a new terminal from the "file manager" window. If you don't see a file manager window, right click on the background, select files, then select file manager.

  1. Click on the "file" tab in the file manager and select "open terminal". You see a window with a "%" prompt pop up. This is the equivalent of the DOS command prompt in MS Windows.
  2. Click on the terminal window and type "tcsh" - I won't explain what this is right now - just do it. This should always be the command you type first when a new "terminal" comes up. If "tcsh" doesn't work, type "csh".
  3. Type "pwd" - this command shows you what directory you're currently in.
  4. Type "ls" - this command shows the contents of the current directory - don't be surprised if there's nothing there - that's why we're here! As you might have guessed, "ls" corresponds to "dir" in DOS.
  5. Type "ls -a" - As with MS Windows, there are some hidden systems files that are not usually visible. This command will display all files and directories in the current directory.
  6. Type "ls -l" - This is the same as ls but gives you additional information for each file and folder.
  7. Type "netscape &" - guess what this does! Go to the CSC15 class webpage at If the netscape command doesn't work, see the instructions for remote login at the end of this document.
  8. Download the files "cshrc" and "useqt", which are linked from the homepage.
  9. These files should now be in your home directory. Type ls to verify this.
  10. Now it's time to learn some more basic commands:
    Basic Command Summary
    1. cd : change directory to named directory
      cd .. : go to parent directory
      cd /path : absolute directories begin with "/", the root directory.
      For example, if you are in directory /shared/csc/local, typing "cd .." will take you to the /shared/csc directory. typing "cd" by itself will take you to your home directory.
    2. cp file1 file2 : copies the contents of file1 into a file called file2.
    3. ls : lists directory contents
    4. mkdir dirname : creates a new directory called dirname in the current directory
    5. mv file1 file2 : renames file1 into file2
    6. rm file1 : deletes file1
    7. rm -rf dirname : deletes the named directory and all its contents. Use with care!
    8. pwd : tells you the current directory you're in.
    9. more filename : a quick way to view the contents of a text file.
    Many of these operations can also be performed using the mouse in the "file manager" window. However, you'll need to learn these commands if you want to use the Sun workstations remotely using telnet (I'll show you how to do that later). Besides, all serious computer users know them!

    Let's now practice these commands (please do not deviate from instructions)
  11. Make sure you're in your home directory (type "cd") and that you've downloaded cshrc and useqt into this directory. In the terminal window, type "mv cshrc .cshrc". Now the .cshrc file will not be displayed when you type "ls". This is important - your system will look for this file when it needs certain things.
  12. Type "mkdir csc15" - what does this do? You should creat a directory for this class because you'll be using your account for other classes as well.
  13. Type "cd csc15" - you're now in the directory you created.
  14. Type "cd .." - you're back in the directory you were in before
  15. Type "cp useqt csc15/useqt" - copies the useqt file you downloaded into a file of the same name in the csc15 directory. (Make sure that there's a space between the two file names, and note that there is no "/" before the "csc" - that was a typo in the earlier version).
  16. Figure out on your own how to erase the old copy! (look at the list of commands above!)
  17. Log out. (this will put into effect the .cshrc file you downloaded) Right click on a blank part of the screen and select log out.
  18. Log back in, open a new terminal, and type "tcsh" or "csh" - always type this when you open a new terminal.
  19. Go into your csc15 directory (forgot how to do that? look above!)
  20. Time to write a program.
    To do that you need to learn how to use an editor. A very powerful (though less easy than MS word) editor used by programmers is "xemacs" - type "xemacs &" - you'll see a window come up. (if no window comes up, see the instructions for remote login at the end of this document.) You should recognize a toolbar with familiar buttons such as "file", "edit" and "help". Select "file" and open a file called "firstprog.C"
  21. Type in the first program provided on the first attached sheet. You do not have to type in all the comments marked with //, but put your name in comments at the top.
  22. save it under the name "firstprog.C" in the csc15 directory.
  23. Make sure you're in the csc15 directory. Now you need to "compile the program" by typing "g++ firstprog.C -o firstprog". Did you get any errors? If you did, that means you had a typo while copying the program, so go back and edit the program, save it, and try again. (If g++ returned with "command not found", try "CC" instead, or see the instructions for remote login at the end of this document.)
  24. Run the sucessfully compiled program by typeing "./firstprog".
  25. Change the line while "(counter < 10)" to "while (counter < 5)". Recompile and run it again. Congratulations! You're on your way to becomming a real computer geek! (just kidding).
  26. Quit emacs (click the "file" menu option)
  27. Time to write a program with Qt! Start emacs again and copy the second attached program. Save it as "secondprog.C". The Compilation procedure is different than for a standard C++ program:
  28. In your csc15 directory, type "source useqt"
  29. Compile the program with "qtcompile secondprog" - note, do NOT include the ".C" suffix of the file name - this is important! If there are errors and you need to recompile again, you do NOT have to source useqt - that's only necessary before the first time you compile. Do not worry (for now) about any "warning" messages. But other error messages can not be ignored - again they indicate that you didn't copy the program correctly.
  30. Run the program with "./secondprog &" Try making the window smaller (manipulate lower right corner) and bigger. Can you make it bigger?
  31. Change the line in the program concerning "setMaximumSize" to see if you can get the program to allow the window to get bigger.

You are to turn in the printouts of the two programs you typed in and modified. Make sure the printouts have your names on it. To print, type (in the same directory where the file resides) print204 filename. This will always print to the lazer printer in Adams 204.

Final Note: you are expected to remember what you learned today, for these skills are required throughout the semester. Practice these skills further on your own time.

Instructions for Remote login :

Some of the machines in Adams 204 are not configured correctly. They do not have some software such as netscape available. For these machines, you need to log in to a remote host instead, effectively making your computer a "thin client". You need to log out first if you are currently logged in. At the log in prompt, select options, then remote login. Select "enter host name" under remote login, and type in "". Remember this procedure. Note: to reset the machine to its normal state, select options and choose "return to local host".