Other UNIX commands
To copy a file: use the
cp
command.1For example, to copy the file
CreateSubdirectories.C
from the directory~seligman/root-class
to your current working directory, type:> cp ~seligman/root-class/CreateSubdirectories.C $PWD
In UNIX,
$PWD
means the results of thepwd
command.2
To look at the contents of a text file: Use the
less
command.3This command is handy if you want to quickly look at a file without editing it. To browse the contents of file
CreateSubdirectories.C
, type:> less CreateSubdirectories.C
While
less
is running, type a space to go forward one screen, typeb
to go backward one screen, typeq
to quit, and typeh
for a complete list of commands you can use.
To get help on any UNIX command: type
man <command-name>
While
man
is running, you can use the same navigation commands asless
. For example, to learn about theless
command, type:> man less
To edit a file: I suggest you use
emacs
.4 For example, to edit the file CreateSubdirectories.C:> emacs CreateSubdirectories.C
This may appear to “lock up” your UNIX window. If this is an issue, either create a new UNIX window or learn about ampersands at the end of a command line.
The
emacs
environment is complex, and you can spend a lifetime learning it.5 For now, just use the mouse to move the cursor and look at the menus. When you get the chance, I suggest you take theemacs
tutorial by selecting it under the Help menu.
Tip
Are you quitting emacs after you change a file, only to start up the editor again a moment later? Hint: look at the File menu. If you’re editing many files, try opening them all with File->Open File… and switch between them using the Buffers menu. Remember to use File->Save once in a while.
Learn how to cut and paste in whatever editor you use. If you don’t, you’ll waste a lot of time typing the same things over and over again.

Figure 3: http://xkcd.com/378 by Randall Munroe.
If you’re feeling bored, type Meta-x butterfly
in emacs and see what
happens.
- 1
As students began to use laptops, I noticed that many of them had an interesting misconception: The
cp
command copies a file from one place to another on the same computer. It does not copy a file from a remote server to your laptop! For that you usescp
; useman scp
to learn more. Note that if you’re working on a remote server such as the ones at Nevis, there’s no reason to usescp
for this tutorial.- 2
A period (
.
) is the usual abbreviation in UNIX for “the current directory” (did you remember that..
means “the directory above this one”?) but many students missed the period the first time I taught this class.- 3
If the name is confusing: the
less
command was created as a more powerful version of themore
command.- 4
If you’re already familiar with another text-based UNIX editor, such as
nano
orvim
, you can use it instead.If you’re not using a remote UNIX server and you’re editing files on your laptop, make sure you’re using a plain-text editor. If you use an editor whose default mode is to not save files in plain text (Microsoft Word is one example; the poorly-named TextEdit on the Mac is another) you’re going to get confused. If you don’t already have such an editor, I suggest Notepad++ on MS-Windows and the free version of BBEdit for the Mac.
On a Mac,
emacs
is built-in and you can use it from within Terminal. You’ll get the screen-based version instead of the window-based version; do not put & after the command. You’ll also need to take the tutorial immediately, as suggested inemacs
’ “Welcome” screen, since the editing keypresses for the screen-basedemacs
are not obvious.- 5
I’ve spent two of your lifetimes already, and the class has just started!