Java Reference
In-Depth Information
Example 6.1 Attempt to hardlink between mounts
$ ln example /boot/sample
ln: creating hard link `/boot/sample' to `example': Invalid cross-device link
$
Example 6.2 Symlinking /etc/passwd
$ ls -la
total 8
drwxrwxr-x 2 mschwarz mschwarz 4096 Jul 8 15:30 .
drwx------ 50 mschwarz mschwarz 4096 Jul 8 15:29 ..
$ ln -sf /etc/passwd passwd
$ ls -la
total 8
drwxrwxr-x 2 mschwarz mschwarz 4096 Jul 8 15:31 .
drwx------ 50 mschwarz mschwarz 4096 Jul 8 15:29 ..
lrwxrwxrwx 1 mschwarz mschwarz 11 Jul 8 15:31 passwd -> /etc/passwd
$ cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
...
etc.
What we did here works just like a hard link, but note the attributes
on the file: The l indicates a symbolic link, and the permissions are
read/write/execute for user, group, and other (or for “world” for short). How-
ever, these permissions apply to the link, not to the file. Just as with hard links,
there is only one set of permissions on the file, and these are on the file that is
pointed to, not on the pointer.
One interesting difference between symlinks and hard links is that sym-
links do not increment the link count on a file. If we remove /etc/password
(a very bad idea, by the way), the symlink would be unaffected, but an attempt
to open or read the symlink would not work, because it points at nothing that
exists. This is called a dangling symlink .
Symlinks may refer to symlinks, and thus you need to be cautious to avoid
circular symlink chains. All the shells we have used on Linux report circular
symlinks as “too many levels of symbolic links,” which sounds like a process
exceeding its stack limits but handling it gracefully.
Search WWH ::




Custom Search