How can I set things up so the buffer being used to run an inferior shell will be autosaved periodically to a file?

The file to save in could be named "shell-2018-01-22".

I thought this would be trivial but it seems the autosave concept is deeply tied into the visiting file concepts which of course, doesn't apply for the buffer being used by the inferior shell.

The reason is because twice this past month my emacs had died. Usually its not a big deal but in these last two cases, it was frustrating enough to prompt me into trying to figure out a solution.

  • I've never tried it, but it looks like real-auto-save might be able to do this, or you could use it as a starting point for your own solution. If assigning the shell's buffer to a file breaks things, you might want to implement something that makes a copy of the shell buffer, save that copy to a file, then discard it.
    – benzado
    Jan 23, 2018 at 0:05

1 Answer 1


I posted an email to the emacs-devel mailing list and the answer is amazingly simple. Just do M-x auto-save-mode.

I did that and now there is a file called #%2Ashell%2A#38994078EmN# in the directory. Another alternative they suggested is just write the shell buffer out to a file. i.e. C-x C-w /some/path and that will save the buffer to a file. In my testing, that also kicks on auto-save mode.


Your Answer

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

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