Listing Files On A Remote Server With Emacs

I use TRAMP all the time to edit files on a remote machine: it’s quick, easy, and pretty much transparent. I just learned something new that in retrospect should have been obvious. You can obtain a listing of remote directories simply by opening the directory.

Normally, when using TRAMP, you specify a file 【Ctrl+x Ctrl+f/host:directory/file and Emacs fetches the file for you to edit and then copies it back to the remote host when you save it. But if you specify just a directory, 【Ctrl+x Ctrl+f/host:directory, Emacs will either open a Dired buffer for that (remote) directory or show you a list of files in the minibuffer. I haven’t figured out the exact rule but it appears that the first time you go to the remote host you get the Dired buffer. After that you get the list of files. If you want the Dired buffer you can always get it with 【Ctrl+x d/host:directory.

The nice thing is that this Dired buffer acts just as a local one does. You can drill down into subdirectories and choose a file to edit as normal. All the usual Dired commands work just as if you were in a local directory: you can search, mark, copy, delete, and so on.

Considering that my usual procedure is to SSH into the remote host and run ls to find the exact name of the file that I want to edit, this is a real time saver. Just another example of the power of Dired, this time assisted by TRAMP.

This entry was posted in General and tagged . Bookmark the permalink.

3 Responses to Listing Files On A Remote Server With Emacs

  1. foo says:

    Completion works over ssh too, so C-x C-f and TAB will give you the names.

  2. Phil says:

    A lot of things “Just Work” with Tramp, including shell operations. If you’re in a remote buffer, then M-x shell opens a shell on the remote host; M-x rgrep runs the find/grep on the remote host; etc, etc…

    Basically, Tramp is awesome.

  3. Michael Albinus says:

    If you are interested in finding a remote file, “M-x find-name-dired” or “M-x find-grep-dired” with a remote directory will be your friends. I use them every day.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>