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

View Things Topic

  1. Run Shell in Emacs
  2. Spell Checking
  3. View Linux man Page
  4. View Info Page
  5. View Image File
  6. View Image Thumbnails
  7. Eww Web Browser
  8. Open File in External App
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.