1

How to start Emacs from the command line with and open file trough ssh?

What I usually do is first open Emacs and do: C-X C-F /ssh:my_remote_server:/file.txt RET

How can I directly open the file from the command line doing something similar to:

emacs --remote "/ssh:my_remote_server:/file.txt"

3
  • I guess this approach can help for you. emacs.stackexchange.com/questions/25033/… Jan 17, 2021 at 20:08
  • 1
    Doing emacs -Q "/ssh:my_remote_server:/file.txt" works fine for me. Where/how does it break for you?
    – NickD
    Jan 17, 2021 at 20:52
  • @NickD yes that work, could you do an answer with this?
    – ucsky
    Jan 18, 2021 at 8:27

1 Answer 1

2

To open a file when starting a new instance of Emacs you can generally do:

emacs "/ssh:server:file"

as described in man emacs:

SYNOPSIS
       emacs [ command-line switches ] [ files ... ]

If you use Emacs daemon and want to open a file within an existing instance of Emacs you can do emacsclient "/ssh:server:file" as well but it will cause emacsclient to block the terminal:

$ emacsclient "/ssh:freebsd:Makefile"
Waiting for Emacs...

If you want to use emacsclient without blocking the terminal do:

emacsclient --eval "(with-current-buffer  (window-buffer) (find-file \"/ssh:server:file\"))"
3
  • it is workin. Is there an advantage of doing this in comparison of what NickD propose in comment?
    – ucsky
    Jan 18, 2021 at 8:35
  • @ucsky: it works as well, see edited answer Jan 18, 2021 at 12:29
  • It's the same thing: the only reason I added -Q was to ensure that there was nothing in any init file that would cause a problem.
    – NickD
    Jan 18, 2021 at 15:16

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.