UPDATE 2013.02.09: Via the comments I’ve come to know that it is possible with
ln after all as long as you don’t combine a tilde (
˜) and quotes in the source path (which I did because some of my folders have spaces in their name). Just escape any spaces with a
\ and the tilde will resolve fine. No need for one to install hardlink. Thanks @mathias!
A simple command-line utility that implements directory hardlinks on Mac OS X
Because OS X’ built-in
ln is crippled. Install via:
git clone git://github.com/selkhateeb/hardlink.git make sudo make install
# create hardlink hardlink source destination #remove hardlink hardlink -u destination
Thanks to this one I can now
~/Kaho/ws2 instead of
~/Dropbox/Kaho/Lesactiviteiten/WS2 - Serverside/2012-2013 🙂
In the situation you described, couldn’t you have done the same with a simple symlink? That’s what I do for my
dotfilesdirectory. It lives in
~/Projects/dotfiles, but I have it symlinked as
~/dotfilesso I can simply
cd dotfilesfrom my home directory to get there.
$ ls -lsa | grep dotfiles
8 lrwxr-xr-x 1 Mathias staff 32 Jul 29 2012 dotfiles -> /Users/Mathias/Projects/dotfiles
(Or just create an alias:
alias ws2="cd ~/Dropbox/Kaho/Lesactiviteiten/WS2\ -\ Serverside/2012-2013".)
Symlinks are fine and dandy but turns out one can’t
cdinto a symlink on the shell (at least I couldn’t).
Another reason I create a hardlink is to shorten the path displayed in Terminal (cfr. your .bash_prompt). That way I can keep the username+path+branch on a single line, even with large font sizes (which I use when my MBP is connected to a projector so that even my students in the back can see what happens).
The symlink solution I described fulfills all your requirements 🙂
Strange it’s not working for you…
Tilde expansion won’t work in strings that are wrapped in single quotes. Try this instead:
ln -s ~/Dropbox/Kaho/Lesactiviteiten/WS2\ -\ Serverside/2012-2013 test
You can also do
ln -s ~/'Dropbox/Kaho/Lesactiviteiten/WS2 - Serverside/2012-2013/' test. Like Mathias said, just don’t quote or escape the tilde.
… and once again Mathias turned out to be the hero that saved the day. Thank you, dear Sir!
Also: Why Apple, Why? That’s stuff that should work out of the box.
> Also: Why Apple, Why? That’s stuff that should work out of the box.
this isn’t an apple thing. this is a *nix thing. the tilde is a shell expansion – if you single quote it, no expansion happens. Think of ‘~’ just like you would ‘$HOME’ or ‘*fish’ – they’re all literal strings.
on the other hand, double quotes ARE expanded. “~” “$HOME” “*fish” (the later is a shell glob, if you’re not familiar with that – and would expand if it matches something, otherwise is literal)
I tried your ‘hardlink’ utility on OSX 10.6.8. The link option worked fine. But now I can’t unlink.
At first I tried to just do another ‘hardlink’ command to the same destination, but it complained that ‘File exists’. Then I tried to ‘rmdir’ the new link: ‘Operation not permitted’. I’ve decided that I can use a symlink for the effect I want, but I just can’t get rid of this experiment.
I just wanted to leave a note thanking you for making this! Super useful. I use hardlinks on linux and windows all the time and was struggling with ‘ln’ on OSX before I found out that ln is crippled.
Leave a comment