Sometimes I have a long pathname, and want to shorten it by some precreated symlink to a directory in the pathname. Specifically, given a pathname /path/to/file, and a symbolic link /symlink to a directory /path/to in the pathname, is there a command which can return an equivalent pathname /symlink/file, to makes use of the symlink?

(optional, my focus is on the above for now) Furthermore, given a pathname, and a directory of symbolic links to directories, is there a command which can find out if there is any symlink to "a directory appearing in the pathname", and if yes, return an equivalent pathname using the symlink?


  • 1
    Given multiple possible choices, what should this utility do? Optimize for shortest length? Deepest link / fewest directories? – Jeff Schaller Feb 17 at 0:16
  • (IMHO, the first question could be independent of the 2nd). – Jeff Schaller Feb 17 at 0:17
  • 1
    To canonicalize symlinks you would use readlink. Have a look at its options -f, -e, -m. – Freddy Feb 17 at 0:37
  • @Freddy What is "canonicalize symlinks "? – Tim Feb 17 at 0:38
  • 1
    It seems like you are searching for a symlink to a specific directory, which is almost impossible, since that needs to search the whole VFS tree. – 炸鱼薯条德里克 Feb 17 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.