What is the "canonical path"?

This is a matter of theory. I searched the Internet without satisfaction, I just want to understand what this jargon is. I saw examples of Java, JSON, etc., but I could not find on Google and here in StackOverflow a simple explanation, I do not need code = P

So, the absolute path is the path to a specific file or location that describes the full path to it, the full path and the OS that depends on it (the absolute paths for Windows and Linux, for example, are different) Relative, specify the path to the file or location that it described from the current locations .. (two dots) indicating an excellent level in the directory tree. This has been clear to me for several years.

When searching, I even saw that there are canonized files! All I know is CANONICAL means something like “by the rules” or something like that.

Can someone please enlighten me in terms of the theory of canonical material, please? =) THANKS !!

PD (So, it was not just a random Ubuntu name) XD

PD2 Unfortunately, I can’t give an answer to everyone, I gave it to the one that helped me better understand the concept, but thanks very much to everyone =)

+46
theory path relative-path absolute-path
Aug 23 2018-12-21T00:
source share
3 answers

The whole point is to do something “canonical” so you can compare two things. For example, both ../../here/bar/x and ./test/../../bar/x may all refer to the same place, but you cannot perform textual comparisons in two ways. However, if you turn them into your canonical representation, they will both become ../bar/x , and we see that they really all refer to the same thing.

In short, it often happens that you have many ways of addressing one thing, in which case you can define a canonical representation that is unique and which allows you to get a col & shy; lections of such things.

(If you are looking for more examples, all mathematics is full of “canonical” constructions for all kinds of objects and very much for the same purpose. Perhaps this Wikipedia article may provide some advertising and shy directions.)

+60
Aug 23 2018-12-12T00:
source share

A good way to determine the canonical path would be: the shortest absolute path (short, in terms of string length).

This is an example of the difference between an absolute path and a canonical path:

absolute path: C:\abc\..\abc\file.txt
canonical path: C:\abc\file.txt

+9
Aug 23 2018-12-12T00:
source share

Which canonical path (or its difference from the absolute path) depends on the system.
Typically, if the (full) path contains aliases, shortcuts, or symbolic links, the canonical path resolves all this to the actual directories to which they refer.
Example: if /bin/a is a symbolic link, you can find it anywhere you ask for an absolute path, for example. from java.io.File # getAbsolutePath , while the real file (i.e. the actual link object), i.e. usr/local/bin/a , will be returned as a canonical path, for example. from java.io.File # getCanonicalPath

+5
Aug 23 2018-12-12T00:
source share



All Articles