Unix Notes

Getting going with Unix/Linux

Unix terminology

Important: change password with the passwd command!

Here are some of the most common unix commands:

Creating files

There are several options for creating and editing files:

Working in Emacs

Most keyboard shortcuts for commands use either ^ (control key - held while typing next character) or esc (escape key - press and release before typing next character). Editing takes place in a buffer; save the buffer to overwrite previous file version. Cutting and pasting also works from a buffer (clipboard equivalent).

^x^s  save file
^x^c  exit
^g    clears the commands, use this several times if you get in a weird state

^p  previous line (up)
^n  next line (down)
^b  backwards (left)  
^f  forward (right)  
^a  beginning of line 
^e  end of line

esc %  search & replace
^s  incremental search
^k  kill to end of line (stored in buffer)
^y  yank and insert from the buffer
^@  set mark (to indicate beginning of a selection)
esc w  copy selection (region from mark to cursor, copied to buffer)
^w  cut selection (stored in buffer, use ^-y yank to paste)

Working in Vim

Vim has two distinct "states," called "insert mode" and "command mode". In insert mode, vim works much like Windows Notepad, or any other simple text editor; when you press keys, the corresponding letters and symbols are added to the file at the location of the cursor. Command mode is used for all the more advanced editing features such as cut/copy/paste, or moving the cursor around.

Hitting the escape key always switches you to command mode; if you're not sure what mode you're in, hit escape, and then you'll know you're in command mode. If you're in command mode, hitting the 'a' key will get you into edit mode. To save your file, get to command mode, type ":w", and hit enter. To quit the program, get to command mode, type ":q", and hit enter. In command mode, here are a few of the things you can do:

File commands - type ":", then the command letter, then hit enter
:w save (write your file)
:q quit (exit from vim)
:q! force-quit (discards unsaved changes)

Commands to switch to Insert mode:
i start inserting text before cursor location
a start inserting text after cursor location
o start inserting on a new line below the current one
O start inserting on a new line above the current one

Movement commands:
h left a character
j down a line
k up a line
l right a character
f<char> find first instance of <char> on this line
0 beginning of line
$ end of line
w next beginning of word
e next end of word
% jump to matching paren

Editing Commands:
yy copy (yank) line
y<number>y copy <number> lines
y<movement command> copy text covered by the movement command (e.g. yw to copy the next word)

dd cut (delete) line
d<number>d cut (delete) <number> lines
dw delete word

p paste (after cursor)
P paste (before cursor)