Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a fast way (keyboard shortcut) to open a terminal emulator (in my case urxvt) in the same directory as the file in the current emacs buffer?

share|improve this question
up vote 11 down vote accepted

The combination M-! allows you to launch shell commands. You could use it to launch a separate urxvt.

M-! urxvt RET

I just tried it with xterm (I don't have urxvt) and it did open in the same directory as the file in the buffer.

If you want to define a shortcut add something similar in your init file:

(global-set-key (kbd "C-c s") (kbd "M-! urxvt RET"))

In my case I bound the shortcut to: Ctrl+C - S.

share|improve this answer

The emacs command M-x shell will start a shell in a new buffer (or switch to an existing shell buffer, if there is one). If it's a new shell buffer, it'll be started in the directory of the file being visited in the current buffer. If it's an existing shell buffer, it'll still be in the directory where you left it after last using it. In order to always get the behaviour you want, remember to kill the shell buffer when you're done with it (C-x k)

If M-x shell is too much typing, you can set a global key to start a shell for you. Something like (global-set-key (kbd "C-x S") 'shell) in your startup file should do it (but be careful not to mask another useful command with your shortcut!)

share|improve this answer

I usually use M-x term.

You can also checkout:

  • M-x terminal
  • M-x shell

M-x term is effectively launching a terminal emulator written in elisp. From the help:

M-x ... RET Start a terminal-emulator in a new buffer. (term PROGRAM)

term is an interactive compiled Lisp function in `term.el'.

Start a terminal-emulator in a new buffer. The buffer is in Term mode; see `term-mode' for the commands to use in that buffer.

Type C-c b to switch to another buffer.

share|improve this answer
Thanks, I didn't know M-x term, it seems nice but is not exactly what I want. I want to start not a shell (for example bash or zsh in an emacs buffer but a terminal emulator (xterm or urxvt...). – student Aug 7 '12 at 12:50
@student have a look at multi-term – Ulrich Dangel Aug 7 '12 at 14:10

I wanted to run a dedicated terminal application, konsole. I wanted to open a new tab in konsole if it is running, or fire-up one if it is not.

Since I was younger back then I split the implementation between emacs and bash. I call the following defun from emacs:

(defun bk-konsoles ()
  "Calls: bk_konsoles.bash -- which starts new tab in a running konsole,"
  (let ((curDir default-directory))
    (shell-command (concat "bk_konsoles.bash \"" curDir "\" 2>&1 > /dev/null & disown") nil nil)
    (kill-buffer "*Shell Command Output*")))

The defun calls bash script, bk_konsoles.bash:


myPath=`echo $@ | sed 's/.$//'`

runningKonsole=`ps -e | grep konsole`
if [ "$runningKonsole"!="" ]; then
    if [ "$@"!="" ]; then
        konsole --new-tab --workdir "$myPath" 2>&1 > /dev/null
        konsole --new-tab 2>&1 > /dev/null
    wmctrl -a " – Konsole"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.