I know I can run M-x pwd which will give me Directory ~/ or something like that. Can I get it without the "Directory" bit?

Thank you very much.

4 Answers 4


You could also add

(setq my-initial-directory default-directory)

to your Emacs init file.

In that way, you could later access the directory where Emacs was launched by evaluating my-initial-directory..


Check the default-directory variable.

  • Thank you very much. However, default-directory changes with each found file. I'd like to find the "working directory" where Emacs have been launched. Apr 30, 2015 at 9:37
  • 3
    Emacs doesn't rely on that notion. For a lot of people, it was launched 2 months ago. Don't close Emacs unless you're rebooting.
    – abo-abo
    Apr 30, 2015 at 9:39
  • 1
    +1 M-x pwd just prints the message with the value of the variable default-directory Apr 30, 2015 at 10:45

I just found out I can do (getenv "PWD") on Linux on bash. I'm not sure if there's a better (more platform-agnostic and Emacs) way to do so.


You can evaluate (call-process "pwd" nil t), e.g. typing M-: (call-process "pwd" nil t) RET. This will run Unix pwd command and insert its output at the point in the current buffer, if the buffer is not read-only. It's not clear from the question what for and why you need the current directory without Directory prefix.

  • Thank you, but I'd like to save it in a variable. Apr 30, 2015 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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