2

The issue of resolving symlinks (symbolic links) is often addressed on this forum, and on others. Related are the concepts of relative, absolute (or full), and canonical (or resolved) pathnames. Two now standard utilities are available, for example in GNU core utilities, to resolve symlinks, and, among other things, produce canonical pathnames: readlink and realpath.

Why do we need canonical paths?

Can you give examples where canonical paths are required, and non-canonical absolute paths will not be acceptable?

Side question: why do people get "canonical path" answers for "absolute path" questions? But is this technology or sociology ?

jasonwryan
  • 73,126
babou
  • 838

1 Answers1

2
  1. You need canonical paths to determine the volume a file system object resides on (if you want to do it that way; there are other ways).
  2. If access rights refer to paths (like with Apache) then you need canonical paths.
Hauke Laging
  • 90,279
  • Can you expand on #1? – dubiousjim May 29 '13 at 00:37
  • @dubiousjim /data/README.txt can be on a volume which is mounted on /home. You need to know whether it happens to be a link to e.g. /home/user/README.txt. – Hauke Laging May 29 '13 at 08:50
  • Thanks, I meant could you expand on the parentheses :-). – dubiousjim May 29 '13 at 22:07
  • 1
    @dubiousjim You can ask the kernel directly: man 2 lstat (dev_t) – Hauke Laging May 29 '13 at 22:27
  • Is there anything wrong with using df for that purpose. – babou May 30 '13 at 20:55
  • Is there anything wrong with using df for that purpose ? Well, I realize I should have made my original question more precise. I was thinking mainly of a shell user. Canonical paths seem possibly more likely to be useful when programming in C. But both contexts sare interesting. My initial question was motivated by my puzzlement over the design of readlink as a shell command, compared to realpath. But then the explanation is probably that designing the shell utilities should be different from designing a library. – babou May 30 '13 at 21:18
  • @babou I don't see any problem abusing df for that. – Hauke Laging May 30 '13 at 21:30