Very basic notes on Unix

This introduction assumes that you have got a working account set up for you on a Unix system, that you've managed to log in, and that the cursor is now sitting in a "command window" (you should see a prompt, ending in > or %, that may contain other information about your user name or the machine you're logged into). There are also various graphical user interfaces (GUIs) that you may run into on a Unix system such as OpenWindows or CDE. Some of these GUI tools may allow you to move files, etc., in a way that you're more familiar with from PCs. There's probably a basic tutorial on your machine about the GUI; this material covers only the command-line stuff. Material that is specific to the Eno network (Sun workstations in EEB at Princeton University) is marked with an E.

Listing files and changing directories

In Unix, files are stored in a hierarchical system of directories ("folders" in the Windows/Mac world). At any given time the system keeps track of your current directory, which you can figure out by typing pwd. The "root" of the hierarchical tree is called /; your home directory will be something like /homespace/home/joe. "Up" means moving towards the root of the tree, from sub-directories to directories (e.g. from /homespace/home/joe to /homespace/home), "down" means moving from directories to sub-directories (e.g. from /homespace/home/joe to /homespace/home/joe/stats).

To list the files in the current directory:

ls
To get a long listing, with owner, date, permissions, and last modification date:
ls -l
To change to other directories:
    cd foo            (change to a directory within the current directory)
    cd /home/joe/foo  (change to a directory specified by "absolute path":
                       / means "the top of the filesystem hierarchy")
    cd ..             (go up one directory)
    cd ../foo         (go up one directory and change to directory foo)
    cd ~fred          (change to fred's home directory) 

Moving, copying, removing files

 
     mv foo1 foo2     (move/rename a file in the current directory)
     cp foo1 foo2     (copy foo1 to foo2 in the current directory)
     rm foo1          (erase file foo1)

Creating and editing files

There are a variety of text editors in Unix, many of them are powerful and hard to get started with. I recommend pico, which is fairly simple and has the advantage of listing all of its commands at the bottom of the screen. vi and emacs are more powerful; vim is an enhanced version of vi.

Finding files and searching in them

     grep string foo    (print all lines in file "foo" containing
                          string "string")
     find

Printing

Permissions; changing permissions

     chmod

Compiling & running programs

      gcc
      make

Wildcard expansions

      *
      TAB

Scripts