-1

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?

matanox
  • 582
  • Is there aparticular reason you need to dereference the symlinks to directories on your own? ls does that automatically. – Wieland May 11 '19 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. – matanox May 11 '19 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. – matanox May 11 '19 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 '19 at 21:13

1 Answers1

1

It should work with simple quoting like:

ls "$(readlink "symlink to target")"
Freddy
  • 25,565
  • 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! – matanox May 11 '19 at 20:54