Emacs: Run Shell in Emacs

By Xah Lee. Date: . Last updated: .

This page is a tutorial on running OS shell inside Emacs. On Linux, this is usually Bash. On Windows, this is cmd.exe, or can be PowerShell.

emacs shell 2016-07-18
Emacs Alt+x shell

Running Shell in Emacs

How to run a shell inside emacs?

Alt+x shell.

When in shell, to run the previous shell command, press 【Ctrl+】.

How to run a second shell inside emacs?

Alt+x universal-argumentCtrl+u】 first before you Alt+x shell.

Can i run ssh inside emacs?

Alt+x term (this will create a new term for each command call). Then, you can run {ssh, top, vi, …}. You can even start another emacs.

To exit term, press 【Ctrl+d】.

When in term-mode, Alt+x describe-modeCtrl+h m】 to see full list of its keys.

[see Emacs: Difference between shell, term, eshell]

I do not recommend using term, because normal emacs keys won't work. Use a dedicated terminal app for ssh.

What's the advantage of running shell inside emacs?

see Why Run Shell in Emacs?

How to call a shell command once?

Alt+x shell-commandAlt+!】 to run just 1 shell command.

For example, try Alt+x shell-command “ls”.

How to send current text selection to a shell command?

Select a region, then Alt+x shell-command-on-regionAlt+|】.

For example, select a region, then type 【Alt+| wc -l Enter】. This will print line count of region.

You can have the result replace the selected region. to do that, do Alt+x universal-argumentCtrl+u】 before calling the shell on region command.

Shell on Microsoft Windows

On Windows, by default, when you Alt+x shell, it starts cmd.exe.

How to have unix shell commands on Windows?

Alt+x eshell.

see Emacs: M-x eshell

My shell doesn't work in Windows?

Most problems are probably caused by incorrect environment variable setup. See: Emacs in Microsoft Windows FAQ.

Misc

How to invoke GUI menu in text terminal?

Alt+x menu-bar-openF10】 to open menu.

see Emacs: Command to Open Menu

Shell Topic

  1. Emacs: Run Shell in Emacs
  2. Why Run Shell in Emacs?
  3. Emacs: Difference between shell, term, eshell
  4. Emacs: M-x eshell
  5. Emacs: View Linux man Page
  6. Emacs: Interactive Abbrev
  7. Emacs: File Manager, dired
  8. Emacs: Batch Rename Files
  9. Linux: Basic Shell Commands

View Things Topic

  1. Emacs: Run Shell in Emacs
  2. Emacs: Spell Checking
  3. Emacs: View Linux man Page
  4. Emacs: View Info Page
  5. Emacs: View Image File
  6. Emacs: View Image Thumbnails
  7. Emacs: Eww Web Browser
  8. Emacs: Open File in External App
Like my tutorial? Put $5 at patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs