I use the realpath command, but it always adds the original input at the end of the path:

$ pwd
$ realpath yosefkl
  • You're asking for a directory inside your current working directory. Try this instead: realpath .
    – penguin359
    Dec 28, 2017 at 7:54

3 Answers 3


You gave realpath a relative path, to a file in the current directory.

The file (which may be a directory) may or may not exist. realpath does not care by default. It reports the path regardless of whether its last element exists.

If you want it to only report paths that exist, use the -e flag:

zanna@toaster:~/playground$ realpath playground
zanna@toaster:~/playground$ realpath ~/playground
zanna@toaster:~/playground$ realpath -e playground
realpath: playground: No such file or directory

That's because you're giving it a path that doesn't exist, so it simply prints out the current directory and whatever you gave it, assuming that would be the path. Note that the man page specifies that:

Print the resolved absolute file name; all but the last component must exist

So it allows execution with a nonexistent target. To illustrate, consider these examples:

$ pwd
$ ls
lost+found  terdon
$ realpath terdon
$ realpath nonExistentDir

Or, to duplicate what you did:

$ pwd
$ realpath terdon

No, it only tells you that the path to the (probably non-existent) file yosefkl located in the current directory (/homes/yosefkl) is /homes/yosefkl/yosefkl. Try

realpath "$PWD"

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.