Return to the Section 101 Homepage or the Introduction to Emacs and the Shell.
Shell Reference Sheet
Introduction
A single command to the Shell usually takes the form:
> program options arguments
> represents the prompt.
program may be something like "emacs" or "javac".
options modify the behavior of that program. They often take the form -x or --option.
arguments generally act as the input to the program. An argument might be a file name, for example.
Common Commands
Here are some of the most common and essential commands:
* > pwd - Print the path of the current directory.
* > ls - List all the files in the current directory.
* > cd - Make your home directory the current directory.
* > cd directory - Change the current directory to directory.
* > mkdir directory - Make a new directory called directory.
* > cp source destination - Copy the source file to the destination.
* > cp -r source destination - Copy the source directory and everything in it to the destination directory. The -r stands for "recursive".
* > rm file - Remove the file.
* > rm -r directory - Remove the directory and everything in it. Again, the -r stands for "recursive".
* > rmdir directory - Removes directory. Will fail if directory is not empty.
* > program - Runs program. Favorites include "emacs", "javac", "java", and "firefox".
More Details
Most programs will take an -h or --help option and output information on the options they offer and their proper use.
Backgrounding
Unless told to do otherwise, the Shell will wait until a command finishes before returning control to the user. For many programs, such as "ls" or "cd", the run time is so short that it makes no difference. But for others, especially those that launch their own window, such as Emacs or Firefox, the Shell will become unusable until the program is exited. This can be inconvenient.
To alleviate this, run the program "in the background". This is done by appending an ampersand (&) to the end of the command to launch the program. For example:
> emacs &
Following the launch of a program in the background, control of the Shell will immediately return to the user. It is then possible to run other commands and even launch more programs in the background.
Directories
The tilde (~) is essentially an abbreviation for the path to your home directory. That is, for example,
> cd
(Which sets your home directory as the current directory) is equivalent to
> cd ~
Every directory has two special "pseudo-subdirectories":
* . and ./ represent the current directory. These are often used as the destination argument to "cp". For example:
> cp otherFile .
* .. and ../ represent the directory that contains the current directory. These are often used with "cd" to move to the parent directory. For example:
> cd ..
More
The "more" program takes text from some source and displays it a screenfull at a time.
For example, to display the contents of a file, do the following:
> more fileName
It is also possible to pass more the output of another program. This is particularly useful when that program outputs too much to display at once. javac, for example, might output too many errors to fit on the screen at once. To use more in this way, do the following:
> program options arguments | more
| is called a "pipe" and, in general, passes the output of the program on its left as the input to the program on its right. In this case, it passes the output of program as input to more.
* There are many different Shells (such as Bash, the Korn Shell (ksh), the C Shell (csh), etc), each offering its own set of features.
* All Shells offer a scripting language, which can be helpful in automatic tasks and managing a system.
* Some shells offer tab autocompletion and understand Emacs commands (See the
Emacs Reference Sheet).
Return to the Section 101 Homepage or the Introduction to Emacs and the Shell.