next up previous contents
Next: Working with Directories: the Up: EMACS as a Work Previous: EMACS as a Work   Contents

Unix Commands in Shell Window

To execute Unix commands one at a time, type ``M-!'' (escape !) and press return. EMACS then opens a window called ``*Shell Command Output*'' where it display the output of your command. Press ``C-x 1'' (one window) to get rid of this window. Now we are ready to discuss the ``shell'' mode, the interactive facility to run Unix command. To start the shell, do ``M-x shell''. This creates a buffer (window) called ``*shell*'', and you see the Unix prompt in this buffer. For most part, this is exactly like the normal Unix command interface, except you can use EMACS to edit the commands. But note the following:
Shell Character EMACS Keystrokes action
C-c C-c C-c interrupt the current process
C-d C-c C-d end-of-file
C-u C-c C-u delete the whole line
C-z C-c C-z suspend the current process

That is, the normal control keys typed in Unix shell have to be prefixed by ``C-c'' in order for them to work within EMACS. You also need to know the following window commands of EMACS to switch from one window (or buffer) to the other. Here the words ``window'' and ``buffer'' are used interchangeably.
Keystrokes action
C-x 0 delete the current window
C-x 1 keep only this (one) window
C-x 2 divide the current window horizontally into two
C-x o move to the other window
C-x C-f find file and load into current window (original content removed)
C-x i insert file at the cursor position
C-x C-w write buffer content to file
C-x C-b list all buffers
C-x b switch to the buffer specified

Note that when we issue directory commands in the shell mode, it could alter the default directory of EMACS. As a rule, if the cursor is in a file, the default directory of EMACS is the directory that the file is in. When you start a shell, EMACS automatically puts you in its default directory. Suppose now you give the shell command cd /home/src/emacs/lisp and try to view a file with C-x C-f. The default directory for finding a file will be /home/src/emacs/lisp.
One big advantage of shell mode is that you can start a command and then switch to a different window to continue editing while the command is running. The ``shell buffer'' doesn't even need to be on the screen; just type M-x shell to get the buffer back. This is more convenient than running commands in the background, because you don't need to worry about output from the background process obscuring the screen; its output is saved neatly in the shell buffer.
next up previous contents
Next: Working with Directories: the Up: EMACS as a Work Previous: EMACS as a Work   Contents
Arthur Chou 2001-09-04