Copying, moving, deleting files
| Traversing and moving between directories
| Invoking programs including editors and compilers | Edit, compile, debug, and run a C++ program | |
This section comes in several parts. You will login, practice some UNIX commands, and write a simple C++ program. This document is only a brief introduction to many tools. You will need to spend some time on your own experimenting further to become comfortable with the tools. You should consult the OIT online help page for more information.
In this document, commands that you type will be in a font that looks like this, sometimes commands may be quoted --- "like this" --- do not type the quotes, just type what is between them. When instructed to type something, press the return key after typing it.
You will see one of the following machines to login to (or if none appears, enter one of these)
godzilla.acpub.duke.edu
kiosk.acpub.duke.edu
(Hint: Use tabs to move between fields). Type your duke login-id, then a tab, then type your password (your password is not displayed).
A unix command shell window should be displayed and a message indicated that you have successfully logged on.
To enter a command, type after the prompt in one of the xterm windows. You should see a prompt that may look similar to
[1] rodger@godzilla2%except rodger should be replaced by your login-id and the number and machine name may be different. If you make a mistake when typing a UNIX command, use the delete key or the arrow keys to correct it.
At any time, you can type cd (with no arguments) to return to your home directory. To work on an assignment you'll normally copy one or more files into a directory in which you'll do work for the assignment. The copy command is cp so from within your lastday directory (for example) type (do not forget the trailing dot: "."):
Type ls to see that the files were copied. You should see a new file called Makefile. We will use the Makefile to compile programs in this course. This Makefile will automatically link to libraries that will be used in this course. You can use it without modification for any C++ program you write as long as the complete program is in one file. If you write a program in multiple files, you will need to modify the Makefile slightly to tell it which files to combine together to make your program.
xemacs &
An xemacs window should appear (please be patient!). You can use the arrow keys and the mouse to move around in the xemacs window.
Use the file menu to load a file (even one that does not exist
yet). Click and hold the menu and choose Open File before releasing
the mouse button. (alternatively, you can use cntrl-x cntrl-f, that is
hold down the control key and press x followed by f as a substitute for
using the menu.)|
| The prompt for Find file: appears in the small minibuffer window at the bottom of the xemacs window. You should also see a path which might be ~/ or ~/groupcps6/aug29/. If you do not see this, consult with a TA because you may not be in the correct directory. You can edit what appears in the minibuffer with arrow/delete keys. You will create a file named lorax.cpp. To do so complete the
path in the minibuffer so that it reads ~/groupcps6/aug29/lorax.cpp
and press return.
| Enter the C++ program shown previously. Be careful that you type it just
as it appears. You will notice sometimes after you type something, the
cursor will "automagically" move to another position to indent
properly. When you type a "}", the cursor always jumps back to
the "{" for a second so you can see if the "}" matches
with the correct "{". These are features of the xemacs
editor meant to make it easier for you to complete your programs.
| If you make a mistake, use the arrow keys or mouse to move around and
edit in the window. You can use the mouse to position the cursor
within xemacs by clicking in the window where you want to type. You
can also use the arrow keys and the scroll bar to move around. | |
In general, you should always have an xemacs window open. Unless you are logging off, there is seldom a reason to quit xemacs. You can, however iconify (make small) the window by clicking the mouse on the dot-button in the upper right of the window. This works for any window. Double-clicking on an icon opens that application.
Until you save your file, it is stored in a temporary buffer (the region in xemacs in which you are typing). When you believe the C++ program is correct, save it by clicking the File button at the top of the xemacs window, and then selecting Save Buffer. A message that the buffer has been written should appear in the minibuffer. You should save your program often to ensure none of your changes are lost inadvertently. You will not be granted any leniency if you lose your work because you did not save it properly. You can type cntrl-x cntrl-s to save instead of using the mouse.
When the program has been successfully compiled continue with the next section.If there are multiple error messages, fix the first one only and then recompile. Sometimes one error causes the compiler to list additional errors that are not really errors.An example of an error message is:lorax.cpp:5: unterminated string or character constant lorax.cpp:5: possible real start of unterminated constant This message tells you the name of the file (lorax.cpp), the line number the error occurred near (line 5) and a guess as to what is wrong. You do not need to worry about where line 5 is since clicking on the error message takes you there.
If you do not have any errors with the first compile, you might want to modify the program so that there is an error. For example, remove a semi-colon and then compile the program.
| In an xterm window, type ls to see the files in you aug29
directory. You should see both lorax.cpp and lorax. The file lorax is an executable program. You might also see a file called lorax.cpp~. This is a backup copy of your program that xemacs automatically creates. It is not an exact copy, but rather a copy before you made your most recent changes. To run any executable program, type its name in your terminal window, so
type lorax to execute this program.
| You can type ls -l to see how big the files are and when
they were created. | |
![]()