PDA

View Full Version : Symbolic Link FAQ's?


petey
05-21-2002, 05:01 PM
Coming from an non-UNIX background, I'm not exactly clear on exactly what a symbolic link is.

- How is a symlink different from a Classic Mac OS Alias?

- Is it just plain text of the absolute path of the file?

- What's the difference between Absolute and Relative symlinks? How about Hard Links?

- While I know it's easy enough to create a symlink in the CLI, anyone aware of any GUI apps that create/deal with them? (I do know that LaunchBar has some link creation abilities.)

Marcwic
05-22-2002, 07:09 AM
[QUOTE]Originally posted by petey
[B]Coming from an non-UNIX background, I'm not exactly clear on exactly what a symbolic link is.

- How is a symlink different from a Classic Mac OS Alias?

I acts like the file so a symbolic link called /users/bobby/pics/ that links to /Applications/ImageViewer/Images/People/Me


/users/bobby/pics/me.jpg

would be the same as

/Applications/ImageViewer/Images/People/Me.jpg

wheras with classic mac links that wouldn't work, it's just a link for the finder to use.

I can't help with your other questions, sorry!

ashevin
05-22-2002, 10:18 AM
Hi,

Disclaimer: I'm no expert on Aliases, so I'm just describing what I've observed.

1) A symbolic link is a filesystem object that is a pointer to some other filesystem object. It exists at the filesystem layer, and the filesystem takes care of traversing the links.

A Finder Alias seems to be an application object, created and manipulated either by the Finder or some layer between the Finder and the filesystem. It is really a file that is treated in a special way by the Finder. They can point to any object, but they are not equivalent to that object. For example, you cannot 'cd' to an Alias in the terminal. Not a good technical explanation, but as I said, I'm no expert :)

2) A symlink is stored as a plaintext string, but it is not a file. On many filesystems that have them, they are stored as part of the directory entry itself, if the link is few enough characters.

3) The only difference between an absolute and relative link is whether is starts with a slash ( '/' ). An absolute link (with a '/') causes the filesystem to resolve the link starting with the root ( '/' ) directory. A relative link is resolved starting with the directory that the link is in.

4) A hardlink is a very different filesystem object. Unix filesystems have an object called an inode which describes where all the pieces of a file are and various other attributes such as atime, mtime and ctime (access, modified and create times). A directory entry is simply a pointer to this inode. A hardlink is nothing more than the directory entry that is pointing to this inode. Everytime a file is created, at least one hardlink exists in the form of the directory entry that is used to create it. Unix filesystems simply allow you to add to that initial hardlink.

With filesystems that support hardlinks, a file is not really deleted until all hardlinks are removed. The 'rm' command really just removes the hardlinks that you specify to the command. The filesystem takes care of releasing the blocks used by the files if the link count goes to zero. rm doesn't have any direct influence on that at all.

5) The Finder can deal with existing links, but I don't think that it can create them. In fact, it thinks that a link I have to a directory is simply a Folder (according to Show Info).

- Avi

rusto
05-22-2002, 07:09 PM
Your #5 is quite true but we can make believe the Finder can make a symlink. :)

Here is an AppleScript iLoafer and I came up with over the the Apple AppleScript discussion group that you can save as an application and then put in your Finder toolbar. Drag an item to it that you want to make a symlink of, then a dialog box opens allowing you to choose a destination folder for the symlink:

on open (item_list)
tell application "Finder"
repeat with theItem in item_list
set targetPath to (get POSIX path of theItem)
display dialog "Enter link name:" default answer "" buttons {"Cancel", "Create Link"} default button 2
copy the result as list to {linkName, button_pressed}
set chosen to choose folder with prompt "Pick location of symlink"
set chosenFolder to (get POSIX path of chosen)
do shell script "ln -s \\" & targetPath & " " & chosenFolder & "/" & linkName & ""
end repeat
end tell
end open