Jump to: [A] [B] [C] [D] [E] [F]

Unix Basics

Here are basic commands to navigate UNIX and edit files.

File/Directory Manipulation

When you open a terminal window, you're placed at a command prompt:

[cs421-ta@nova ~]$

The prompt shows your username, the host you are logged onto, and your current location in the directory structure (your path). The tilde character is shorthand for your home directory. Note your prompt may look slightly different. To make a directory, use the mkdir command. Use cd to change to that directory:

[cs421-ta@nova ~]$ mkdir foo
[cs421-ta@nova ~]$ cd foo
[cs421-ta@nova ~/foo]$

Use ls to see a listing of the contents of a directory, and touch to create an empty file:

[cs421-ta@nova ~/foo]$ ls
[cs421-ta@nova ~/foo]$ touch hello_world
[cs421-ta@nova ~/foo]$ ls
hello_world
[cs421-ta@nova ~/foo]$ cd ..
[cs421-ta@nova ~]$

Download python_basics.zip into your home directory (note: the zip file's name may be slightly different when you download it). Use unzip to extract the contents of the zip file:

[cs421-ta@nova ~]$ ls *.zip
python_basics.zip
[cs421-ta@nova ~]$ unzip python_basics.zip
[cs421-ta@nova ~]$ cd python_basics
[cs421-ta@nova ~/python_basics]$ ls
foreach.py
helloWorld.py
listcomp.py
listcomp2.py
quickSort.py
shop.py
shopTest.py

Some other useful Unix commands:

The Emacs text editor

Emacs is a customizable text editor which has some nice features specifically tailored for programmers. However, you can use any other text editor that you may prefer (such as vi, pico, or joe on Unix; or Notepad on Windows; or TextWrangler on OS X; and many more).

To run Emacs, type emacs at a command prompt:

[cs421-ta@nova ~/python_basics]$ emacs helloWorld.py &
[1] 3262

Here we gave the argument helloWorld.py which will either open that file for editing if it exists, or create it otherwise. Emacs notices that this is a Python source file (because of the .py ending) and enters Python-mode, which is supposed to help you write code. When editing this file you may notice some of that text becomes automatically colored: this is syntax highlighting to help you distinguish items such as keywords, variables, strings, and comments. Pressing Enter, Tab, or Backspace may cause the cursor to jump to weird locations: this is because Python is very picky about indentation, and Emacs is predicting the proper tabbing that you should use.

Some basic Emacs editing commands (C- means "while holding the Ctrl-key"):

You can also copy and paste using just the mouse. Using the left button, select a region of text to copy. Click the middle button to paste.

There are two ways you can use Emacs to develop Python code. The most straightforward way is to use it just as a text editor: create and edit Python files in Emacs; then run Python to test the code somewhere else, like in a terminal window. Alternatively, you can run Python inside Emacs: see the options under "Python" in the menubar, or type C-c ! to start a Python interpreter in a split screen. (Use C-x o to switch between the split screens, or just click if C-x doesn't work).

If you want to spend some extra setup time becoming a power user, you can try an IDE like Eclipse (Download the Eclipse Classic package at the bottom). Check out PyDev for Python support in Eclipse.