Command Line

In a command-line interface, you communicate with the computer by typing in commands. When using a graphical desktop, you can open a command window to provide a command-line interface. Your commands are actually carried out by a program called a "shell". There are a variety of shells, which vary somewhat in the commands that they understand. On our Linux system, we use the shell program "bash". Bash runs automatically when you start the "Terminal" program (in the "Applications" menu, under "Accessories".).

The bash shell prints out a prompt, which includes your user name, the name of the computer, and the directory that you are currently working in. When the bash shell first starts, you are working in your "home directory". If your user name is user, then the full name of this directory is "/afs/afs.hws.edu/home/user", but we've set up things so that just "/home/user" will also work. In fact, for convenience, the name of the home directory can be abbreviated as the single character "~".

In Linux, "/" is the name of the so-called root directory, which contains all the files on the entire system. "/home" refers to the directory named "home" inside the root directory. This directory contains all the home directories of all the users on the system. "/home/user" refers to the directory named "user" inside the directory named "/home". You can continue this pattern to subdirectories of your home directory. For example: /home/user/javawork. File names work similarly. A file named exercise1.java in the directory /home/user/javawork would have the full name /home/user/javawork/exercise1.java. The point of a current "working" directory is that you don't have to use the full name for files and subdirectories in that directory. If your working directory is /home/user, and if it contains a subdirectory named "javawork", you can use the name "javawork" instead of the full name "/home/user/javawork". You could refer to a file named "exercise1.java" inside the javawork directory as "javawork/exercise1.java". Of course, if you changed your working directory to javawork, then you could refer to this file simply as "exercise1.java".

Bash has several shortcuts that you can use while entering commands. Type the first few characters of a command or file name and press the Tab key. Bash will complete the name for you and add a space. If there are several possible matches, it will complete as much of the name as possible (without a space). That is, it will add the characters that all the possible matches agree on, if any. You can then press Tab a second time to get a list of possible matches. You can use the arrow keys while entering a command. The up and down arrow keys will move you though a list of previously entered commands, so you can retrieve an old command and edit it. Bash remembers these commands even after you log out, so they will still be there the next time you log in.

Bash has many commands. First of all, any program name is a command. You can run the program by typing in its name. To run the Netscape browser, for example, just enter the command "netscape". Commands can have "arguments" -- extra information typed after the command name. For example, when you run Netscape, you can provide a Web address as an argument. Netscape will open and display the specified web page. For example, use the command "netscape http://math.hws.edu/" to view the page at address http://math.hws.edu/. You should note, by the way, that both commands and file names in Linux are case sensitive. You can't type "Netscape", with an upper-case "N", when the name of the program is "netscape".

Here are some of the most common commands used in bash. Something written in brackets, such as [file-name], describes an argument for the command. Where you see [file-name], for example, you should type the name of a file.

You might want to look at the AFS file system page for information about special commands that are available for interacting with AFS.

If you enter a command in the bash shell, that command must ordinarily be completed before you can give another command. However, it is possible to run a command "in the background". This starts the command running, but doesn't hang up the bash shell. You will immediately get a new prompt so that you can enter another command. To run a command in the background, just add a "&" to the end of the command. This is only really useful when you are running a program such as a text editor. For example, the command "nedit exercise1.java &" will open a window where you can edit the file exercise1java, and you will still be able to type more commands while the window is open. (Later, when you close the window, you will get a funny message in the command-line window to tell you that the program has ended.)

With many commands, you can enter multiple file names as arguments. For example, the command "nedit ex1.java ex1.html" will open edit windows for both of the files ex1.java and ex1.html. To make working with large numbers of file easier, bash uses the character "*" as a wildcard that stands for any sequence of zero or more characters. If you use a * in a name, bash will replace that name with a list of all the files that match the name. For example, "nedit *.java" lets you edit every file in the current directory whose name ends with ".java". But be careful! The command "rm *" will delete every file in the working directory!