When connected to an old remote system with Tramp, the buffer shows no files. With tramp-verbose set to 6, I looked at the Tramp debug buffer, then found (anonymized):

13:27:21.657267 tramp-send-command (6) # /bin/ls --color=never --dired -algGh /user/user/. 2>/dev/null

When I remove 2>/dev/null and execute the above command, I get:

/bin/ls: invalid option -- h
Try `/bin/ls --help' for more information.

ls on the remote system is part of GNU fileutils 3.16 and does not support the option -h. For my regular system I have configured dired+:

(dired-listing-switches "-algGh")

Is there any way to use a different configuration for that remote system?

What I tried, unsuccessfully:

  '((dired-listing-switches nil)))
 '(:application 'tramp :machine "example.com")

How I connect to the old system

The system only supports connection by SSH v1. For that purpose, plink and pscp do support the option -1. So I added to tramp-connection-properties:

("/plink:user@example\\.com:" "login-args"
  ("-l" "%u")

Now I can connect to /plink:[email protected]:.

My solution

Thanks to Michael Albinus’ answer, I came up with:

(defun my-dired-before-readin-hook ()
  (let ((remote-host (file-remote-p default-directory 'host)))
    (when (string= remote-host "example.com")
      (setq dired-actual-switches "-algG"))))
(add-hook 'dired-before-readin-hook 'my-dired-before-readin-hook)

3 Answers 3


And not to forget the hint in the Tramp manual:

Emacs computes the ‘dired’ options based on the local host but if the remote host cannot understand the same ls command, then set them with a hook as follows:

 (lambda ()
   (when (file-remote-p default-directory)
     (setq dired-actual-switches "-al"))))
  • I added detection of the correct host. Find the solution added to my question.
    – feklee
    Commented Mar 24, 2021 at 5:35

Set tramp-verbose to 6, and rerun the test. There will be a Tramp debug buffer. Look for messages tagged with (6), they contain sent commands, and the responses. Perhaps you'll see what's going on.

  • Thanks! I updated my question. Have to dig around. Guess this is not a new problem.
    – feklee
    Commented Mar 19, 2021 at 5:36
  • Tramp doesn't send ls ... -algGh .... I guess you have configured dired to do so. Check variable dired-listing-switches and alike. Commented Mar 19, 2021 at 10:13
  • Right. I forgot about my own Emacs configuration tweaks from long ago. Now I wonder wether I should rephrase my question or close it. The new question is how to tell Dired+ to use a different ls command when connected to that machine.
    – feklee
    Commented Mar 19, 2021 at 14:00
  • It's up to you how to continue. Likely, my answer would be "use connection-local variables", but I cannot say yet, because it would require testing for a recipe. And it would require to know which Emacs/Tramp version you use. Commented Mar 19, 2021 at 19:04
  • I rephrased the question, and added the Tramp version number. Although using the keyword connection-local variables, I can probably figure it out myself, I think it would be nice if you add an answer here, so that we have a complete Q&A.
    – feklee
    Commented Mar 21, 2021 at 4:12

Something like this works for me:

(defconst tramp-connection-local-default-dired-switches
  '((dired-listing-switches . "-al")
    (dired-actual-switches . "-al"))
  "Default connection-local dired switches.")


(defun tramp-dired-connection-local-variables-apply ()
  "Set `dired-listing-switches' in dired buffers."
  (when (file-remote-p default-directory)
    (let ((enable-connection-local-variables t))
       `(:application dired
         :protocol ,(file-remote-p default-directory 'method)
         :user     ,(file-remote-p default-directory 'user)
         :machine  ,(file-remote-p default-directory 'host))))))

(with-eval-after-load 'dired
   '(:application dired)


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.