-1

This question already has an answer here:

I have a bunch of symlinks pointing to various directories. Each of the target directories happen to have a space in them, I have not created them like that, but they are being received as such via zip files.

This boils down to the following command not working, due to the spaces:

ll $(readlink <symlink name>)

And in general, I am looking for a way to more, tree, ls, and similar commands, using the symlink names such that these bash commands will operate on the target directory of the symlinks. It sounds odd but I failed finding existing answers so I'm not sure this is actually supported in bash.

Is there any elegant way to refer to symlinks in a way that bash would always simply dereference them to their targets, without relying on command-specific flags?

marked as duplicate by ilkkachu bash May 11 at 21:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Is there aparticular reason you need to dereference the symlinks to directories on your own? ls does that automatically. – Wieland May 11 at 20:49
  • with ls, can't seem to get the dereferencing to work, for some reason. it will only show the symlink's definition, but not follow it. maybe the spaces in the target directory names are to blame, not sure. – Matan May 11 at 20:56
  • I fail to see why guessing is involved. An answer has been even accepted, obviously that person felt lesser need to guess, no offense. I think this question is practically done. – Matan May 11 at 21:06
  • @Matan, frankly, from your question, I wasn't sure if you wanted the problem of symlinks not working properly (which is what I was trying to ask about), or the problem of that command substitution not working. The answer to the second one would have been found in one of the most highly-voted and most often referenced answers on the site. – ilkkachu May 11 at 21:13
1

It should work with simple quoting like:

ls "$(readlink "symlink to target")"
  • I will miss the tab completion conveniences (which aren't as sophisticated to follow the symlink while at the same time not scrambling due to the spaces), but this actually works. Thanks a lot! – Matan May 11 at 20:54

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