Other UNIX commands

  • To copy a file: use the cp command.1

    For 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 the pwd command.2

  • To look at the contents of a text file: Use the less command.3

    This 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, type b to go backward one screen, type q to quit, and type h 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 as less. For example, to learn about the less 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 the emacs tutorial by selecting it under the Help menu.


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.

xkcd real_programmers

Figure 3: http://xkcd.com/378 by Randall Munroe. If you’re feeling bored, type Meta-x butterfly in emacs and see what happens.


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 use scp; use man 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 use scp for this tutorial.


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.


If the name is confusing: the less command was created as a more powerful version of the more command.


If you’re already familiar with another text-based UNIX editor, such as nano or vim, 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 in emacs’ “Welcome” screen, since the editing keypresses for the screen-based emacs are not obvious.


I’ve spent two of your lifetimes already, and the class has just started!