Computer Science 15-112, Spring 2012
Class Notes: Getting Started in 15-112
Getting Started in 15-112
print "Uh oh! # ERROR! missing close-quote
Python output:
SyntaxError: EOL while scanning string literal
print 1/0 # ERROR! Division by zero! Python output:
ZeroDivisionError: integer division or modulo by zero
print "2+2=5" # ERROR! Untrue!!! Python output:
2+2=5
Python output:Works:
NameError: name 'math' is not defined
Python output:
2.2360679775
Key | Command |
h or Left | Left |
l or space or Right | Right |
k or Up | Up |
j or Down | Down |
0 | Start of line |
$ | End of line |
nG or :n | Go to line number n |
i | Insert at cursor |
a | Insert (append) after cursor |
I | Insert at beginning of line |
A | Insert (Append) at end of line |
ESC | Exit insert mode (switch back to command mode) |
x | Delete current cursor position |
dd | Delete current line |
ndd | Delete n lines |
p | Paste ("push" last text cut/deleted) at the cursor |
u | Undo last change |
ctrl-r | Redo |
/text | Search for text |
n | Search for next occurrence of text |
:w | Write file |
:w! | Overwrite file (ignoring warnings) |
:wq | Save (if necessary) and quit |
:q | Quit if saved (or warn if unsaved) |
:q! | Quit without saving (be careful!) |
Command | Description |
whoami | Print login id of current user |
hostname | Print name of current host (computer) |
users | Print user names of all users on current host |
pwd | Print present working directory (where am I?) |
cd dir | Change directory to dir |
cd ~ | Change directory to user's home directory (~) |
ls | List files in the current directory |
ls -alst | List files with lots of useful information |
ls dir | List files in the directory dir |
mkdir dir | Make a directory named dir |
rmdir dir | Remove the directory named dir (must be empty) |
vim file | Use vim to edit the given file |
cat file | Print (concatenate) the file(s) to standard output |
more file | Print the file, one page at a time |
cp file1 file2 | Copy file1 to file2 |
cp -r dir1 dir2 | Copy (recursively) directory dir1 to dir2 |
mv file1 file2 | Move (rename) file1 to file2 (may be directories) |
rm file | Remove the file |
man cmd | Display the manual pages for cmd |
history | Print recent history of shell commands |
up/down arrows | Navigate history of shell commands (also ctrl-p/ctrl-n) |
cmd | Run the command cmd eg: /afs/cs.cmu.edu/academic/class/15112-f11/bin/hello or: /usr/bin/vimtutor |
./cmd | Run the command cmd in the current directory |
ln -s cmd | Make a symbolic link to cmd in the current directory |
alias name cmd | Make an alias with the given name for the given command eg: alias hi /afs/cs.cmu.edu/academic/class/15112-f11/bin/hello |
alias | List all aliases |
unalias name | Remove the alias with the given name |
clear | Clear the terminal screen |
date | Display the current date and time |
finger user | Print information about user (use Andrew id for user) |
ping machine | Test a network connection to the given machine (ctrl-c to stop) |
exit | Exit the shell (and logout if in a login shell) |
logout | Logout of a login shell |
x = 3
print x
x = 3
print "x =", x
print "yikes =", yikes # ERROR! No such variable as yikes
x = 3
print "x =", x
x = 4
print "x =", x
x = 3
y = 4
print "x =", x
print "y =", y
print "x + y =", (x+y)
carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem