Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm a little bit confused with hard/softlinks here. I'm on OSX, have a folder '4' and two links pointing to it:

drwxr-xr-x  4 imm  staff  136 14 Jun 21:24 4
lrwxr-xr-x  1 imm  staff    1 14 Jun 16:56 4.0 -> 4
lrwxr-xr-x  1 507  wheel    1 14 Jun 16:56 Current -> 4

When I follow 'Current' in folder it leads to a completely different location (the path I copied all the stuff from). I'd like 'Current' to point on the folder '4' at the new location.

How can I achieve this?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

You need to remove and recreate the link. You can do this with

rm Current

And then recreate it:

ln -s /path/to/the/new/location Current

You can to use an absolute path (for simplicity).

If you want the path to move when you move the link, then you can use a relative path. Just bear in mind that it stores the relative path and only resolves it from the link's current location when you try to access it.

Edit: since you mention hardlinks, I'll go ahead and introduce them here.

A hardlink is similar to a symlink, in that it still points to a file, but it is limited to the current file system, but also it is faster. A hardlink points to a specific inode on the disk, instead of another location in the filesystem. You cannot have relative hardlinks.

You can consider a basic filesystem as a collection of hardlinks to locations on disk, one per file. Creating additional hardlinks just creates additional pointers to the same file. They are considerably faster because the system knows exactly where on disk the file it needs is (a symlink has to be resolved, and then that new file has to be looked up and resolved), but because of this it's limited only to inodes on the current filesystem.

The filesystem automatically tracks the number of hardlinks pointing to a particular inode, and simply deletes the inode when that count reaches 0.

share|improve this answer
    
Can I use a relative path as well? –  Hedge Jun 15 '11 at 12:33
2  
You can, though it gets somewhat interesting. The relative path is stored, so you have to be mindful if you move the link (say, by moving the parent folder). It will point relative to it's new location, and will not update to continue pointing to the same spot it was before. This might be what you want, or it might not, but I know it confused me a few times at first because I didn't realize it actually stored the relative path, I thought it just resolved it into an absolute path and stored that. –  Darth Android Jun 15 '11 at 12:37
    
That is exactly what I want :) –  Hedge Jun 15 '11 at 12:40
    
Moved that information into the post, since that was actually what you were after. –  Darth Android Jun 15 '11 at 12:44
    
Ok sorry, I didn't want to make it more complicated. Especially on SO you've to be careful how complicated your questions are or you may get no responses. –  Hedge Jun 15 '11 at 12:50

You can just do this:

ln -nfs /path/to/the/new/location Current

where 'Current' is the current symbolic link. The -n and -f options unlink and remove the original 'Current' and allow creation of the new one (-s for soft link).

I realise that the question has been answered and original problem solved a long time ago, but the process of repointing a symbolic link without going through the separate deletion step was bothering me again, and a Google search for the solution threw up this q&a. Hope it helps someone else looking for the answer!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.