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.