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.
- cd [directory-name] -- Change the working directory to the specified directory.
- mkdir [directory-name] -- Create a new directory with the specified name.
- mv [file-name] [name] -- If the second name is the name of an existing directory, this moves the specified file into that directory. If the second name is the name of an existing file, that file is replaced without warning by the specified file. If the second name is not the name of an existing file or directory, then the specified file is renamed to [name]. This command also works for moving and renaming directories.
- cp [file-name] [name] -- If the second name is the name of an existing directory, this copies the specified file into that directory. If the second name is the name of an existing file, that file is replaced without warning by a copy of the specified file. If the second name is not the name of an existing file or directory, then the specified file is copied to a new file named [name]. If you want to copy a directory and all its contents, use the command "cp -a [directory] [name]" The "-a" stands for "all".
- rm [file-name] -- Delete (or "remove") the specified file. To delete an empty directory, use "rmdir [directory-name]". Rmdir can't remove a directory that still contains some items, but you can use "rm -r [directory-name]" to delete a directory and all its contents.
- ls -- lists the files and subdirectories in the working directory. For a long listing with more information about each file, use "ls -l". Files whose names begin with "." are "hidden" files which are not usually shown in directory listings. These files are generally used by programs to store configuration information and special files. If you want to include them in the listing, use "ls -a" or "ls -la". You can list the content of a directory by specifying it as an argument to the ls command: "ls [directory-name]".
- nedit [file-name] -- Starts the text editing program "nedit" to edit the specified text file. If the file doesn't exist, you will be asked whether you want to create it. (Nedit is a graphical user interface program. There are command-line editors such as "joe" and "vi", but they are generally much harder to use.)
- man [topic] -- Show the "manual page" for the specified topic. Man pages contain information about programs, command names, and a few other topics. For example, use "man bash" to learn more about the bash shell. When viewing a man page, hit the space bar to move down one page. Hit "Q" to quit.
- less [filename] -- Let's you view the contents of a text file. Hit the "q" key to quit. Hit the space bar to move to the next screen; hit the "b" key to move back (or use page up and page down keys). To search for the next occurance of a string, hit "/", type the string, and press return.
- exit -- Exit from the bash shell and close the command window. Equivalently, you can just hit CTRL-D.
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!