Up: Karel's home page

Help with UNIX Commands

This page deals with the basics of using the command line in UNIX to do simple things. Here is a list of common Unix commands

There is a web page at Rutgers that answers FAQs (Frequently Asked Questions) about UNIX and the SUN workstations at Rutgers-Camden: FAQ HELP link. There is also information on Unix at New Mexico Tech.

Getting Started

If you have the lush menu in front of you, in order to get access to the UNIX command line, you can issue the command shell. It should be enough to type just the s or sh before you hit RETURN. When you want to return to the lush menu, type exit (that is, exit from the shell).

The Most Basic Commands

At first you will be working in your home directory, so that will be your present working directory at the start. We will bring in commands and information about creating directories later.

Here is a short list of the most basic commands in UNIX. Each is typed at the prompt and followed by pressing the RETURN key.

  • ls -- What's in here? Shows a LiSt of the files in the present working directory.
  • rm filename -- ReMove the file "filename".,
  • cp first second -- CoPy file "first" to file "second" -- makes a copy of the file named "first" and calls it "second".
  • mv first second -- MoVe file "first" to file "second" -- renames the file named "first" so that becomes the file named "second".
  • lpq Line Printer Query -- Returns the name and status of your default line printer.
  • lpr filename Line Printer pRint -- Prints the file named "filename" to your default line printer.
  • lpr -Pxxxx filename -- Line Printer pRint -- Prints to line printer named "xxxx". You may need to specify the whole path to the printer: for example, "/usr/local/bin/lpr -Pcmbsbpf" to print on printer cmbsbpf.
  • Useful Tricks

    One of the most useful tricks in the UNIX shell that is used at Rutgers-Camden is using TAB to complete a partial command or filename. If you have a file with the name "I-am-getting-tired-of-typing", and you want to open it in the emacs editor, then, at the prompt you type emacs followed by a space and then you type the first few letters of the filename, say I-am and then press the TAB key. You must type enough characters so that there are no other files in the present working directory with names that start with the characters that you typed. After you have typed the command, or typed part of the command and used TAB-completion to get the shell to complete your command, you press the RETURN KEY to pass your command to the shell.

    Another useful trick is to keep your working shell useable by typing
    emacs I-am [press TAB KEY] & [hit RETURN KEY] The & (=ampersand) makes UNIX run emacs in the background, which leaves the command line useable in your working shell. The line should look like this before you hit return:
    prompt% emacs I-am-getting-tired-of-typing &
    except that instead of the word prompt you will have something associated with the machine or server that you are using.

    Working with Directories and Paths

    Something to Know About Directories and Paths

    Computers typically organize files by putting them into containers that are called directories or folders. Each container can have other containers inside it. To keep track of what's what, the computer's operating system software uses a tree structure in which the nodes correspond to containers. To specify a container, you have to specify the sequence of edges that you would traverse in going from the root to the node that is associated with the container you want, or, what is the same, you can specify the sequence of nodes between the root and the container's node. That sequence of nodes is called the path that specifies the container. The path is written something like this: top/high/lower/ still_lower/and_so_on, since trees are written upside down in math and computer science. Above any given node, there is just one node, and in UNIX, it is called the parent directory. And one last bit of information: the directory where you are currently working is called, reasonably, "the Present Working Directory".
  • mkdir some_name -- MaKe DIRectory called "some_name" in the "Present Working Directory."
  • rmdir some_name -- ReMove DIRectory called "some_name" in the "Present Working Directory."
  • cd Change Directory
  • cd or cd ~/ -- Change to my Home Directory
  • cd ../ -- Change to Parent Directory (go up one level)
  • cd - -- Change to Previous Directory (toggles between 2 directories)
  • cd yours -- Change to Directory named "yours"
  • pwd -- Where am I? Shows the path to the "Present Working Directory."
  • cp path1/first path2/second -- CoPy file "first", in the directory identified by path1, to file "second" in the directory identified by path2 -- makes a copy of the file with full name "path1/first", puts the copy in the directory identified by path2 and gives the copy the name "second". The copy has full name "path2/second".
  • mv path1/first path2/second -- MoVe file "first", in the directory identified by path1, to file "second" in the directory identified by path2 -- renames the file with full name "path1/first" so that becomes the file with full name "path2/second".
  • Working with Emacs, LaTeX and Document Viewers

    If you have a LaTeX source file, say small2e.tex, then you can process it by giving the command "latex small2e".
    LaTeX will produce a log file that indicates some details of how the file was processed and any errors that need attention. If the process stops, just look carefully at the error indication, type "x" and correct the error in the source file. If the processing does not run into errors, then LaTeX will produce a DVI (that is, DeVice Independent) file, say small2e.dvi. To view small2e.dvi, give the command "xdvi small2e".
    To print small2e.dvi to your default printer, give the command "dvips small2e",
    or if you want to print on a different printer, say printer xxxx, then give the command dvips small2e -Pxxxx.
    Here is a brief reminder of the commands that you can use to compose, process, view, and print when you are working on a LaTeX document:
    1. emacs somefilename.tex &
    2. latex somefilename (The extension .tex can be omitted (a handy feature))
    3. xdvi somefilename or xdvi !$ or even, if you have already given the command in your current session, !xd
    4. -- Go back to the (still open) emacs window to correct errors, or, if there are no errors, skip to step 6 to print your DVI file.
    5. -- Return to step 2.
    6. dvips somefilename --print to your default printer, --or--go to step 7
    7. dvips somefilename -Pxxxx (where -Pxxxx specifies the name xxxx of the printer that you want to use)
    A little trick to make it quicker to do repetitive tasks: press the up arrow key to retrieve the previous command, or press it twice to retrieve the command before that, and so on. This makes use of the history list maintained by the Unix operating system, which tracks the commands (with their arguments) that you have used during the current session.

    The following will include some information arranged alphabetically by topic.

    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z


    A

    Access to my home directory?
    Use the name ~/ to refer to your home directory
    Access to the parent directory?
    Use the name ../ to refer to the parent of the present working directory

    B