I have a symlink

~/link -> ~/a/really/long/path

When I press ^ in the buffer, it takes me to


but I want to go to


Is there a right way to do this?

Another question is, if I'm on a symlink file's buffer, how can I find out the buffer's physical path?

Say I'm reading a markdown file ~/a/really/long/path/readme.md, what command can print out the physical path of it?


I don't know of a command to do this, or a setting that you can modify to make ^ do it.

I'm on MS Windows without symlinks, but you might try defining a command that uses the same definition as dired-up-directory but that converts dired-current-directory to its symlink target by wrapping it in file-truename, which follows symlinks (untested):

;; Same as `dired-up-directory', except for wrapping with `file-truename'.
(defun my-dired-up-directory (&optional other-window)
  "Run Dired on parent directory of current directory.
Follows symlinks for current directory.
Find the parent directory either in this buffer or another buffer.
Creates a buffer if necessary.
If OTHER-WINDOW (the optional prefix arg), display the parent
directory in another window."
  (interactive "P")
  (let* ((dir  (file-truename (dired-current-directory)))
         (up   (file-name-directory (directory-file-name dir))))
    (or (dired-goto-file (directory-file-name dir))
        ;; Only try dired-goto-subdir if buffer has more than one dir.
        (and (cdr dired-subdir-alist)  (dired-goto-subdir up))
        (progn (if other-window (dired-other-window up) (dired up))
               (dired-goto-file dir)))))

If no one offers an existing way to do this, you might want to file an enhancement request to make dired-up-directory be able to do this (i.e., optionally). That could be done via a particular prefix-arg value or via a variable binding. Alternatively, you could just ask for such an alternative command, so users can bind it to a key.

| improve this answer | |
  • Nice code! Thanks for your advice:D – spacegoing Jan 10 '17 at 4:39
  • @Drew How can you do this to also follow the symlink down a directory? – J Spen Jan 13 '19 at 7:41
  • @Drew I can post a new question but I think it is a really simple change and I'm not sure of a function to do this. – J Spen Jan 13 '19 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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