Symbolic link: Difference between revisions
[unchecked revision] | [unchecked revision] |
No edit summary |
No edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 20: | Line 20: | ||
$ pwd |
$ pwd |
||
/dir1 |
/dir1 |
||
$ cd |
$ cd / |
||
/ |
|||
$ cd /dir2/sdirlink1/.. |
$ cd /dir2/sdirlink1/.. |
||
$ pwd |
$ pwd |
||
Line 36: | Line 35: | ||
$ pwd |
$ pwd |
||
/dir2 |
/dir2 |
||
$ cd |
$ cd / |
||
/ |
|||
$ cd /dir2/sdirlink1/.. |
$ cd /dir2/sdirlink1/.. |
||
$ pwd |
$ pwd |
||
/dir2 |
/dir2 |
||
</pre></code> |
</pre></code> |
||
[[Category:Filesystems]] |
Latest revision as of 22:36, 9 July 2023
Filesystems |
---|
Virtual Filesystems |
Disk Filesystems |
CD/DVD Filesystems |
Network Filesystems |
Flash Filesystems |
Introduction
A symbolic link is a special type of file that refers to another file or directory and is most often encountered in UNIX derived/inspired operating systems and their file systems. Symbolic links are real files that contain a path which is automatically resolved when the link is accessed.
Path resolution
There are multiple ways of handling symbolic links during path resolution: Some operating systems maintain the hierarchy of the path leading to the symlink while others substitute the entire hierarchy of the path for that of the target. UNIX-like operating systems handle this in a strange way: The kernel and C library do the latter while some shells maintain a history of path changes and resolve the parent of a symlinked directory as the parent of the symlink.
Example: On a system substituting the hierarchy (Linux, glibc, shown as shell commands for clarity) :
$ ln -T /dir1/sdir1 /dir2/sdirlink1
$ cd /dir2/sdirlink1
$ pwd
/dir1/sdir1
$ cd ..
$ pwd
/dir1
$ cd /
$ cd /dir2/sdirlink1/..
$ pwd
/dir1
On a system maintaining the symlink's hierarchy (posnk (old version), newlib, shown as shell commands for clarity) :
$ ln -T /dir1/sdir1 /dir2/sdirlink1
$ cd /dir2/sdirlink1
$ pwd
/dir2/sdirlink1
$ cd ..
$ pwd
/dir2
$ cd /
$ cd /dir2/sdirlink1/..
$ pwd
/dir2