A Brief Summary of Some Basic UNIX commands A working directory is the directory where you're currently working. For example you may be in the directory ~/cs/cs122/homework. Some basic commands for navigating UNIX's directory structure are: Commands Explanations ---------------------------------------------------------- pwd "print working directory" displays the working directory cd "change directory" changes working directory. For example, cd (changes to your root directory) cd ~/cs122 (changes to the subdirectory cs122 of your root directory mkdir====================================================================="make directory" rmdir "remove directory" ls "list" lists all files in the working directory, except those that begin with a period. To also list files that begin with a period use ls -a cat "concatenate" displays to the standard output the contents of the files listed, e.g., cat prog1.cc test.cc junk will display contents of files prog1.cc, test.cc, and junk pr "print" behaves the same as the cat command except that it does some formatting grep "grab regular expression" can be used to search a file for a pattern. For example, grep fiddle *.tex finds all occurrences in the files that end with extension .tex, and displays to the standard output any line in the file that contains the pattern fiddle man "manual" gives manual information on , e.g., man grep displays manual pages on the command grep cp "copy" to mv "move" to rm "remove' deletes file . rm -i will give prompt before deleting dos2unix Converts a DOS file to a UNIX file, i.e., removes extraneous control characters In UNIX, the standard input may be redirected using <, and the standard output redirected using >. For example, a.out < prog.dat causes a.out to read from the file prog.dat instead of from the standard input (e.g., keyboard), and a.out > prog.out causes a.out to write to the file prog.out instead of the standard output (e.g., monitor). Both input and output can be redirected, e.g. a.out < prog.dat > prog.out Editing Files --------------------------------------------------------------- The preferred editor to use is emacs or xemacs. Emacs commands generally involve the CONTROL key (sometimes labeled CTRL or CTL) or the META key. Rather than write that in full each time, we'll use the following abbreviations: C- means hold the CONTROL key while typing the character Thus, C-f would be: hold the CONTROL key and type f. M- means hold the META or EDIT or ALT key down while typing . Often there is no META, EDIT or ALT key, so instead press and release the ESC key and then type . We write for the ESC key. Important note: to end the Emacs session, type C-x C-c. (Two characters.) To run the emacs tutorial: type C-h t. Compiling C++ Code ----------------------------------------------------------------- We will be using the Gnu g++ compiler. Here is an example $ g++ -c ListA.cpp --- Compiles a module with no executable $ g++ main.cpp ListA.o --- Compiles main.cpp and links with object code --- and creates an executable called a.out $ ./a.out --- Runs the executable Emacs provides a good environment for developing code. In emacs type: M-x compile . You will get a prompt -- Compile command: At this prompt type your command, e.g. Compile command:g++ main.cpp ListA.o A window will be created. If you click the middle mouse button on an error statement, the editor will bounce you to that line.