On Mon, July 11, 2005 11:07 am, Christopher Sawtell said: > On Mon, 11 Jul 2005 10:32, Nick Rout wrote: >> On Mon, 11 Jul 2005 10:18:18 +1200 (NZST) >> >> John Carter wrote: >> > On Mon, 11 Jul 2005, Steve Holdoway wrote: >> > > On Mon, July 11, 2005 8:30 am, John Carter said: >> > >> The file pointed to doesn't have to exist, or may exist on a >> different >> > >> drive. The symlink itself is not a file, it is merely a tweak >> inside a >> > >> directory file. >> > > >> > > Err... a hard link is a duplicate entry to a pre-existing inode >> entry >> > > on that partition. That said, the file *must* exist before hard >> linking >> > > to it. >> > >> > Yup, I was talking about symbolic links (symlink) not hard. >> Destination >> > of hardlink must exist and exist on the same partition. Destination of >> > shambolic link needn't be on same partition, or same drive or even >> exist. >> > >> > Now that I have spotted my mistake and seen that symlinks have there >> own >> > inode number. Question for the group: >> > >> > Without writing my own code, how can I open the symlink file (not the >> > file it points to) with something like "od" to see whats inside it? >> >> I think that all that is inside it is text with the path to the file it >> is linked to. If you look at the length of a symlink, it is always the >> same as the number of characters in the path+file it points to. >> >> The system knows that it is a pointer to another file because it's file >> type is "link". >> >> > Fascinating, I can use the command inode-cat to do this to a >> conventional >> > file, but it freaks with a lseek error if I point it at a symlink >> inode. > > How about something like: > $ echo -e "one\ntwo\nthree\n" > f1 # Make the original file > $ ln -s f1 Soft_Link_to_f1 # Symbolic link to it > $ ln $(stat Soft_Link_to_f1 | grep '^ File:' | cut -d "\`" -f3 | \ > cut -d "'" -f1) Hard_Link_to_f1 > $ ls -li > total 1 > 156634 -rw-r--r-- 2 chris users 15 Jul 11 11:00 Hard_Link_to_f1 > 156635 lrwxrwxrwx 1 chris users 2 Jul 11 11:00 Soft_Link_to_f1 -> f1 > 156634 -rw-r--r-- 2 chris users 15 Jul 11 11:00 f1 > > OK It's still a line and a half, but perhaps easier to understand. > > It begs the question: Is the current behaviour of ln a bug or a feature? > > -- > CS >
ln duplicates a directory entry. The fact that the directory entry that you're duplicating is a symlink is irrelevant. This is basic functionality. As already pointed out, a symlink can point to targets that are illegal for a hard link, like file on a different partition, or a directory. If you want to implement this potentially illegal functionality, then I'd write it as a local wrapper, but because of all the possible exceptions, I'd write it on loads of lines so you could understand it when a new exception is found and needs to be added ( like supporting -n, checking ln aliases... ). My $0.02, Steve -- Windows: Where do you want to go today? MacOS: Where do you want to be tomorrow? Linux: Are you coming or what?
