I use the realpath
command, but it always adds the original input at the end of the path:
$ pwd
/homes/yosefkl
$ realpath yosefkl
/homes/yosefkl/yosefkl
I use the realpath
command, but it always adds the original input at the end of the path:
$ pwd
/homes/yosefkl
$ realpath yosefkl
/homes/yosefkl/yosefkl
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: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:
So it allows execution with a nonexistent target. To illustrate, consider these examples:
Or, to duplicate what you did:
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