How can I get the full path to a symlink without resolving it to the path of the original file?
For example, if I have a directory set up like this:
~$ tree analysis_results/
analysis_results/
`-- Sample1
`-- bar.txt -> /Users/me/foo.txt
If I try to get the full path to bar.txt
, I end up with the path to foo.txt
instead:
~$ readlink -f analysis_results/Sample1/bar.txt
/Users/me/foo.txt
But what I really want is this:
/Users/me/analysis_results/Sample1/bar.txt
Is there a simple way to accomplish this? It looks like I do not have realpath
available, not sure if that program does this, or if there is some other command that works like this.
Things get more complicated when my pwd
is something like:
/Users/me/analysis/peaks/workflow/code
But I want to read the full path to a symlink like:
/Users/me/analysis/alignment/results/Sample1/bar.txt