Augustana University College

COMPUTING SCIENCE 250
Computer Organization and Architecture I


Introduction to Linux, Emacs, and G++


Connecting to Linux by SSH

SSH is a secure protocol for connecting to a login server. Not only is your login password encrypted, but all traffic between your local machine and the server is encrypted.

PuTTY is a Windows client which implements both the telnet and SSH protocols. You can download PuTTY and install it on your home machine in order to connect to the server Berio to do your assignments. When configuring PuTTY, type 'berio.augustana.ca' in the 'Host Name' box, click the 'SSH' radio button, then type 'Berio' (or 'Augustana" or 'My CSC 250 lab machine' or whatever you want to call this connection) in the 'Saved Sessions' box and click the 'Save' button. You may also wish to change some other settings, but it shouldn't be necessary; for example, I like to change the size of the window (select the 'Window' panel) to 40 rows, instead of the default 24.

The Linux Command Line

For an introduction to Unix (including Linux), see UNIX Reference Desk, especially the link to UNIXhelp for Users, developed at the Univ. of Edinburgh.

A brief command summary is provided here for convenience of reference:

passwd
change your password
ls
list the files in the current directory or a specified directory
v
verbose listing (with file sizes, dates) [an alias for 'ls -l']
cd
change the current directory (default: home directory; '..' to go up one level)
pwd
print the name of the current ("working") directory
cat
print the contents of the specified (text) file, or concatenate the contents of a number of files
less
view the contents of a file, a page at a time (see also more, but "less is more")
mv
move (rename) a file
rm
remove (delete) a file
chmod
change the permissions ("mode" bits) of a file (see details)
mkdir
make (create) a directory
rmdir
remove (delete) a directory (or, with the option flags '-rf', an entire subtree [BE CAREFUL])
logout
log out of the system ('exit' also works in most contexts)

The command line editor allows you to edit the current command line or a previous one in a flexible manner:

up arrow
retrieve a previous command
tab
complete the command or file name
backspace
delete the character in front of the cursor
Ctrl-d
delete the character under the cursor
Ctrl-a
go to the start of the line (mnemonic: 'a' is at the start of the alphabet)
Ctrl-e
go to the end of the line (Ctrl-z was already in use for suspending a process)
Ctrl-k
kill (cut) the rest of the line
Ctrl-u
cut from the cursor to the start of the line
Ctrl-y
yank (retrieve, paste) the previously killed (cut) text
Esc y
yank the text which was cut previously to the currently yanked text

WARNING: There is a Unix command named 'test', so don't name any of your own executable files 'test' or you won't be able to run them without some special gymnastics (e.g., you could type './test'). This is because your own directory is usually included in your search path after the directory where the 'test' utility is located. Type 'echo $PATH' to see your current command search path.

Emacs

Emacs is a very powerful, customizable, extensible editor which has many features to support programming in a variety of languages, including automatic indexing of source code and hooks to various compilers. In general, it provides three ways of entering commands to navigate and edit the text:

NOTE: In Emacs manuals, some key combinations are specified as M-x (where 'x' can be any key). The 'M' stands for Meta, meaning an alternate control key. It is usually configured to be 'Alt', but in some contexts the Alt key doesn't work (since it is used for something else) -- in that case, press Esc, then the specified key.

A few of the most commonly used commands are:

Ctrl-g
abort the current command sequence (MEMORIZE THIS ONE FIRST -- keep entering it until you escape from a botched command in the minibuffer)
Ctrl-x Ctrl-c
exit Emacs (with prompting to save any unsaved files)
Ctrl-x Ctrl-f
read a file into the editor
Ctrl-x Ctrl-s
save the current file
Ctrl-x Ctrl-w
write a file under a specified name (like "Save As")
Ctrl-underscore
undo (repeat for multiple undo)
Ctrl-l
redraw (refresh) the screen
Ctrl-s
search for text (incremental search, which jumps forwards as more text is typed)
Ctrl-space
set a mark
Ctrl-w
kill the region from the mark to the current point of the cursor
M-w
copy the region
Ctrl-y
yank the last cut or copied text
M-y
yank the previously cut or copied text
Tab
indent the current line (according to the current mode)
Ctrl-x b
change to another buffer (another file already loaded into the editor)

See the Emacs tutorial [Free Software Foundation,1985] and the GNU Emacs Reference Card for more complete information on using Emacs.

G++

G++ is the GNU C++ compiler. To compile a C++ program named greet.cc such that the resulting executable file is named greet, issue the following command (where '-o' is an option flag, 'greet' is the argument to the option, and 'greet.cc' is an argument to the 'g++' command):

g++ -o greet greet.cc

If the option '-o greet' is not given, then the g++ compiler/assembler places its output in a file named a.out in the current directory.

To stop the compilation process after the compiler has produced assembly language, issue the following command instead:

g++ -S greet.cc