In the terminal, I can do:

$ readlink -f docker-compose.yml

Which outputs:


I would like to have something like that in Emacs so that I can find the file (a similar interface to the great C-x C-f) and then the full file location goes to the clipboard or kill ring. Or the full path is echoed in the mini buffer. Later, it would be possible to find it on messages.

Is there a way to do it?

Obs.: My first instinct was trying to use C-x C-f which is bounded to counsel-find-file in config file. After I find the file and before pressing return, I cannot move the cursor to select the whole file path and copy it. For some reason, it is blocked. See the image below - I can only move the cursor to the white characters:

enter image description here

2 Answers 2


expand-file-name do the similar things like readlink (or file-truename if you want to follow the symlink as mention by @hraban).

If you want to copy file path with a similar interface like find-file, here are two options to achieve it:

  1. use expand-file-name to write your copy path function and add it to counsel-find-file actions and call it through M-o when you select the file. For more details, see ivy actions
  2. use embark and run embark-action w.
  • Is this an Emacs command? I can't find it with M-x expand-file-name. Or, is this an Elisp function? Jun 3, 2022 at 12:30
  • If it is an Elisp thing, how do you use it to achieve my desire? I tried using eval-expression, opening the parens (expand-file-name ....) . But, it did not work out. Jun 3, 2022 at 12:30
  • Ok, I did it in the eshell. But, it was painful. There was no auto-complete to find the file. There must be a better way! Take in notice that I am not even using vanilla Emacs eshell. Jun 3, 2022 at 12:33
  • 1
    Hi, I have updated my answer. Jun 4, 2022 at 4:45
  • 1
    expand-file-name does not work like readlink -f, the latter of which explicitly follows every symlink in its entire ancestry (that's the job of the -f). file-truename does.
    – hraban
    Aug 30, 2023 at 17:52

I think you're looking for file-truename which also does an expand in default-directory unless the input filename is absolute.

  • This is the correct answer to the question in the title
    – hraban
    Aug 30, 2023 at 17:52

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.