Absolute / canonical / relative paths

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
What is the difference between absolute / canonical / relative paths?
I guess that absolute starts with a /. Can it contain /../?
Is a canonical path different from an absolute path in that it can't contain /../?
Is foo a relative path?
Googling posix canonical path didn't turn up much... What are the POSIX references for these terms?
filesystems posix
add a comment |Â
up vote
2
down vote
favorite
What is the difference between absolute / canonical / relative paths?
I guess that absolute starts with a /. Can it contain /../?
Is a canonical path different from an absolute path in that it can't contain /../?
Is foo a relative path?
Googling posix canonical path didn't turn up much... What are the POSIX references for these terms?
filesystems posix
Seems that the stackoverflow question/answer could help you stackoverflow.com/questions/1099300/â¦
â GiannakopoulosJ
Oct 16 '17 at 13:23
See: stackoverflow.com/questions/12100299/whats-a-canonical-path
â JRFerguson
Oct 16 '17 at 13:26
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
What is the difference between absolute / canonical / relative paths?
I guess that absolute starts with a /. Can it contain /../?
Is a canonical path different from an absolute path in that it can't contain /../?
Is foo a relative path?
Googling posix canonical path didn't turn up much... What are the POSIX references for these terms?
filesystems posix
What is the difference between absolute / canonical / relative paths?
I guess that absolute starts with a /. Can it contain /../?
Is a canonical path different from an absolute path in that it can't contain /../?
Is foo a relative path?
Googling posix canonical path didn't turn up much... What are the POSIX references for these terms?
filesystems posix
asked Oct 16 '17 at 13:18
Tom Hale
5,87922576
5,87922576
Seems that the stackoverflow question/answer could help you stackoverflow.com/questions/1099300/â¦
â GiannakopoulosJ
Oct 16 '17 at 13:23
See: stackoverflow.com/questions/12100299/whats-a-canonical-path
â JRFerguson
Oct 16 '17 at 13:26
add a comment |Â
Seems that the stackoverflow question/answer could help you stackoverflow.com/questions/1099300/â¦
â GiannakopoulosJ
Oct 16 '17 at 13:23
See: stackoverflow.com/questions/12100299/whats-a-canonical-path
â JRFerguson
Oct 16 '17 at 13:26
Seems that the stackoverflow question/answer could help you stackoverflow.com/questions/1099300/â¦
â GiannakopoulosJ
Oct 16 '17 at 13:23
Seems that the stackoverflow question/answer could help you stackoverflow.com/questions/1099300/â¦
â GiannakopoulosJ
Oct 16 '17 at 13:23
See: stackoverflow.com/questions/12100299/whats-a-canonical-path
â JRFerguson
Oct 16 '17 at 13:26
See: stackoverflow.com/questions/12100299/whats-a-canonical-path
â JRFerguson
Oct 16 '17 at 13:26
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
6
down vote
POSIX defines âÂÂabsolute pathnameâ as follows:
A pathname beginning with a single or more than two <slash> characters
and âÂÂrelative pathnameâ as follows:
A pathname not beginning with a <slash> character.
ThatâÂÂs all there is to it for relative and absolute paths.
Canonical paths arenâÂÂt defined in POSIX, but the term usually refers to comparable paths, i.e. if you take two paths to a file system object, and convert them to canonical form, the result should be identical if and only if the two file system objects are identical. This involves removing âÂÂ..â as you mention, but it also means resolving symbolic links; so a canonical path could be defined as
A pathname whose components are all real directories or files, excluding âÂÂ.â and âÂÂ..âÂÂ, and whose slashes are not repeated
In POSIX terms, a canonical pathname is effectively a resolved pathname (as long as you accept that canonical pathnames can only be determined for file system objects which exist).
Note that this only works because hard-linked directories arenâÂÂt allowed...
So to answer your questions:
- an absolute path can contain
/../; - a canonical path can not contain
/../, nor can it contain/./,//(except arguably in first position), or symbolic links; foois a relative path.
(Pedantically, they are all pathnames, not just paths.)
Any//or///or any count//â¦//should be converted to (interpreted as) one/. In that sense, any//at the middle of (any) path is valid and permissible.
â Arrow
Oct 16 '17 at 14:19
@Arrow The answer doesn't say that//in a path is not valid or permissible. It only states that they are not OK in a canonical path, and I would agree :)
â marcelm
Oct 16 '17 at 15:40
@marcelm After any repeated/(in the middle of the path) is converted to one/(if any exist), the path strings could be compared, yes. As such, I agree now.
â Arrow
Oct 16 '17 at 16:15
1
It may be worth mentioning paths starting with~. Shells will often expand such paths to absolute paths pointing at users' home directories.
â John Kugelman
Oct 16 '17 at 19:17
You can hard-link files, though, so I don't think you can state "the result should be identical if and only if the two file system objects are identical" as a single file can have more than one canonical/absolute path.
â Andrew Henle
Oct 17 '17 at 12:53
 |Â
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
POSIX defines âÂÂabsolute pathnameâ as follows:
A pathname beginning with a single or more than two <slash> characters
and âÂÂrelative pathnameâ as follows:
A pathname not beginning with a <slash> character.
ThatâÂÂs all there is to it for relative and absolute paths.
Canonical paths arenâÂÂt defined in POSIX, but the term usually refers to comparable paths, i.e. if you take two paths to a file system object, and convert them to canonical form, the result should be identical if and only if the two file system objects are identical. This involves removing âÂÂ..â as you mention, but it also means resolving symbolic links; so a canonical path could be defined as
A pathname whose components are all real directories or files, excluding âÂÂ.â and âÂÂ..âÂÂ, and whose slashes are not repeated
In POSIX terms, a canonical pathname is effectively a resolved pathname (as long as you accept that canonical pathnames can only be determined for file system objects which exist).
Note that this only works because hard-linked directories arenâÂÂt allowed...
So to answer your questions:
- an absolute path can contain
/../; - a canonical path can not contain
/../, nor can it contain/./,//(except arguably in first position), or symbolic links; foois a relative path.
(Pedantically, they are all pathnames, not just paths.)
Any//or///or any count//â¦//should be converted to (interpreted as) one/. In that sense, any//at the middle of (any) path is valid and permissible.
â Arrow
Oct 16 '17 at 14:19
@Arrow The answer doesn't say that//in a path is not valid or permissible. It only states that they are not OK in a canonical path, and I would agree :)
â marcelm
Oct 16 '17 at 15:40
@marcelm After any repeated/(in the middle of the path) is converted to one/(if any exist), the path strings could be compared, yes. As such, I agree now.
â Arrow
Oct 16 '17 at 16:15
1
It may be worth mentioning paths starting with~. Shells will often expand such paths to absolute paths pointing at users' home directories.
â John Kugelman
Oct 16 '17 at 19:17
You can hard-link files, though, so I don't think you can state "the result should be identical if and only if the two file system objects are identical" as a single file can have more than one canonical/absolute path.
â Andrew Henle
Oct 17 '17 at 12:53
 |Â
show 1 more comment
up vote
6
down vote
POSIX defines âÂÂabsolute pathnameâ as follows:
A pathname beginning with a single or more than two <slash> characters
and âÂÂrelative pathnameâ as follows:
A pathname not beginning with a <slash> character.
ThatâÂÂs all there is to it for relative and absolute paths.
Canonical paths arenâÂÂt defined in POSIX, but the term usually refers to comparable paths, i.e. if you take two paths to a file system object, and convert them to canonical form, the result should be identical if and only if the two file system objects are identical. This involves removing âÂÂ..â as you mention, but it also means resolving symbolic links; so a canonical path could be defined as
A pathname whose components are all real directories or files, excluding âÂÂ.â and âÂÂ..âÂÂ, and whose slashes are not repeated
In POSIX terms, a canonical pathname is effectively a resolved pathname (as long as you accept that canonical pathnames can only be determined for file system objects which exist).
Note that this only works because hard-linked directories arenâÂÂt allowed...
So to answer your questions:
- an absolute path can contain
/../; - a canonical path can not contain
/../, nor can it contain/./,//(except arguably in first position), or symbolic links; foois a relative path.
(Pedantically, they are all pathnames, not just paths.)
Any//or///or any count//â¦//should be converted to (interpreted as) one/. In that sense, any//at the middle of (any) path is valid and permissible.
â Arrow
Oct 16 '17 at 14:19
@Arrow The answer doesn't say that//in a path is not valid or permissible. It only states that they are not OK in a canonical path, and I would agree :)
â marcelm
Oct 16 '17 at 15:40
@marcelm After any repeated/(in the middle of the path) is converted to one/(if any exist), the path strings could be compared, yes. As such, I agree now.
â Arrow
Oct 16 '17 at 16:15
1
It may be worth mentioning paths starting with~. Shells will often expand such paths to absolute paths pointing at users' home directories.
â John Kugelman
Oct 16 '17 at 19:17
You can hard-link files, though, so I don't think you can state "the result should be identical if and only if the two file system objects are identical" as a single file can have more than one canonical/absolute path.
â Andrew Henle
Oct 17 '17 at 12:53
 |Â
show 1 more comment
up vote
6
down vote
up vote
6
down vote
POSIX defines âÂÂabsolute pathnameâ as follows:
A pathname beginning with a single or more than two <slash> characters
and âÂÂrelative pathnameâ as follows:
A pathname not beginning with a <slash> character.
ThatâÂÂs all there is to it for relative and absolute paths.
Canonical paths arenâÂÂt defined in POSIX, but the term usually refers to comparable paths, i.e. if you take two paths to a file system object, and convert them to canonical form, the result should be identical if and only if the two file system objects are identical. This involves removing âÂÂ..â as you mention, but it also means resolving symbolic links; so a canonical path could be defined as
A pathname whose components are all real directories or files, excluding âÂÂ.â and âÂÂ..âÂÂ, and whose slashes are not repeated
In POSIX terms, a canonical pathname is effectively a resolved pathname (as long as you accept that canonical pathnames can only be determined for file system objects which exist).
Note that this only works because hard-linked directories arenâÂÂt allowed...
So to answer your questions:
- an absolute path can contain
/../; - a canonical path can not contain
/../, nor can it contain/./,//(except arguably in first position), or symbolic links; foois a relative path.
(Pedantically, they are all pathnames, not just paths.)
POSIX defines âÂÂabsolute pathnameâ as follows:
A pathname beginning with a single or more than two <slash> characters
and âÂÂrelative pathnameâ as follows:
A pathname not beginning with a <slash> character.
ThatâÂÂs all there is to it for relative and absolute paths.
Canonical paths arenâÂÂt defined in POSIX, but the term usually refers to comparable paths, i.e. if you take two paths to a file system object, and convert them to canonical form, the result should be identical if and only if the two file system objects are identical. This involves removing âÂÂ..â as you mention, but it also means resolving symbolic links; so a canonical path could be defined as
A pathname whose components are all real directories or files, excluding âÂÂ.â and âÂÂ..âÂÂ, and whose slashes are not repeated
In POSIX terms, a canonical pathname is effectively a resolved pathname (as long as you accept that canonical pathnames can only be determined for file system objects which exist).
Note that this only works because hard-linked directories arenâÂÂt allowed...
So to answer your questions:
- an absolute path can contain
/../; - a canonical path can not contain
/../, nor can it contain/./,//(except arguably in first position), or symbolic links; foois a relative path.
(Pedantically, they are all pathnames, not just paths.)
edited Oct 16 '17 at 13:54
answered Oct 16 '17 at 13:40
Stephen Kitt
144k22315379
144k22315379
Any//or///or any count//â¦//should be converted to (interpreted as) one/. In that sense, any//at the middle of (any) path is valid and permissible.
â Arrow
Oct 16 '17 at 14:19
@Arrow The answer doesn't say that//in a path is not valid or permissible. It only states that they are not OK in a canonical path, and I would agree :)
â marcelm
Oct 16 '17 at 15:40
@marcelm After any repeated/(in the middle of the path) is converted to one/(if any exist), the path strings could be compared, yes. As such, I agree now.
â Arrow
Oct 16 '17 at 16:15
1
It may be worth mentioning paths starting with~. Shells will often expand such paths to absolute paths pointing at users' home directories.
â John Kugelman
Oct 16 '17 at 19:17
You can hard-link files, though, so I don't think you can state "the result should be identical if and only if the two file system objects are identical" as a single file can have more than one canonical/absolute path.
â Andrew Henle
Oct 17 '17 at 12:53
 |Â
show 1 more comment
Any//or///or any count//â¦//should be converted to (interpreted as) one/. In that sense, any//at the middle of (any) path is valid and permissible.
â Arrow
Oct 16 '17 at 14:19
@Arrow The answer doesn't say that//in a path is not valid or permissible. It only states that they are not OK in a canonical path, and I would agree :)
â marcelm
Oct 16 '17 at 15:40
@marcelm After any repeated/(in the middle of the path) is converted to one/(if any exist), the path strings could be compared, yes. As such, I agree now.
â Arrow
Oct 16 '17 at 16:15
1
It may be worth mentioning paths starting with~. Shells will often expand such paths to absolute paths pointing at users' home directories.
â John Kugelman
Oct 16 '17 at 19:17
You can hard-link files, though, so I don't think you can state "the result should be identical if and only if the two file system objects are identical" as a single file can have more than one canonical/absolute path.
â Andrew Henle
Oct 17 '17 at 12:53
Any
// or /// or any count //â¦// should be converted to (interpreted as) one /. In that sense, any // at the middle of (any) path is valid and permissible.â Arrow
Oct 16 '17 at 14:19
Any
// or /// or any count //â¦// should be converted to (interpreted as) one /. In that sense, any // at the middle of (any) path is valid and permissible.â Arrow
Oct 16 '17 at 14:19
@Arrow The answer doesn't say that
// in a path is not valid or permissible. It only states that they are not OK in a canonical path, and I would agree :)â marcelm
Oct 16 '17 at 15:40
@Arrow The answer doesn't say that
// in a path is not valid or permissible. It only states that they are not OK in a canonical path, and I would agree :)â marcelm
Oct 16 '17 at 15:40
@marcelm After any repeated
/ (in the middle of the path) is converted to one / (if any exist), the path strings could be compared, yes. As such, I agree now.â Arrow
Oct 16 '17 at 16:15
@marcelm After any repeated
/ (in the middle of the path) is converted to one / (if any exist), the path strings could be compared, yes. As such, I agree now.â Arrow
Oct 16 '17 at 16:15
1
1
It may be worth mentioning paths starting with
~. Shells will often expand such paths to absolute paths pointing at users' home directories.â John Kugelman
Oct 16 '17 at 19:17
It may be worth mentioning paths starting with
~. Shells will often expand such paths to absolute paths pointing at users' home directories.â John Kugelman
Oct 16 '17 at 19:17
You can hard-link files, though, so I don't think you can state "the result should be identical if and only if the two file system objects are identical" as a single file can have more than one canonical/absolute path.
â Andrew Henle
Oct 17 '17 at 12:53
You can hard-link files, though, so I don't think you can state "the result should be identical if and only if the two file system objects are identical" as a single file can have more than one canonical/absolute path.
â Andrew Henle
Oct 17 '17 at 12:53
 |Â
show 1 more comment
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398412%2fabsolute-canonical-relative-paths%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Seems that the stackoverflow question/answer could help you stackoverflow.com/questions/1099300/â¦
â GiannakopoulosJ
Oct 16 '17 at 13:23
See: stackoverflow.com/questions/12100299/whats-a-canonical-path
â JRFerguson
Oct 16 '17 at 13:26