Prevent file shortcuts from breaking when files are moved

1

In Ubuntu (and Windows as well), I've noticed that whenever I create a file shortcut, and then move the file, the shortcut stops working, and becomes "broken". Is it possible to create a file shortcut in such a way that the shortcut will automatically point to the file's current location, instead of breaking whenever the file is moved?

Anderson Green

Posted 2012-08-24T02:18:19.647

Reputation: 5 214

This is a cross-platform issue, and not just an Ubuntu-specific issue, but I decided to post it here because I'm currently trying to solve this problem on Ubuntu. – Anderson Green – 2012-08-24T02:19:41.890

It looks like this program might do something like this, but it only works on Windows: http://download.cnet.com/Broken-Shortcut-Fixer/3000-2248_4-75222211.html

– Anderson Green – 2012-08-24T02:22:36.863

Answers

4

Use the ln (link) command without the -s (symbolic) switch. The link will persist when moving the file within the file system.

ln foo baz
mv foo bar

baz will still link to the file originally known as foo.

ubfan1

Posted 2012-08-24T02:18:19.647

Reputation:

There are some restrictions though: hard-links only work within the same filesystem and it's not possible to make hard-links to directories. – Sergey – 2012-08-24T02:34:42.597

@ubfan1 Can you explain what xx, lxx, and yy are supposed to represent here? Should they each be substituted with file names, or left as-is? – Anderson Green – 2012-08-24T03:43:05.623

@AndersonGreen: I took the liberty of changing the placeholder to "foo bar baz" for intended clarity. – Daniel Andersson – 2012-08-24T08:29:14.250

@DanielAndersson Is it possible to do this on Windows, as well as Unix-like operating systems? – Anderson Green – 2012-08-24T18:38:00.140

@AndersonGreen: Well, all POSIX systems as well as NTFS has support for hard links. I have never used it in a Windows context personally, so I don't know how it works in practice, though. There is a command line tool mklink that creates hard links. If you want a GUI, you probably need third party software.

– Daniel Andersson – 2012-08-24T20:02:04.777