Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is there any way to create a hard link in the finder?

A hard link in terminal would be created with:

ln /path/to/file /path/to/newpath

whereas a symlink / alias can be done by holding command and option or

ln -s /path/to/file /path/to/newpath

(though apparently the behaviors of 'alias' and 'ln' are different)

share|improve this question

5 Answers 5

up vote 5 down vote accepted

You could create an Automator service like this:

enter image description here

This takes the selected files and creates hard links to them in the directory where they exist. You can then drag and drop the links to the location where you want them.

This will work for files with spaces in their names, but not for files containing quotation marks in their name.

You can access it from the Finder » Services menu, the context menu, and you can assign it a keyboard shortcut analogous to the L shortcut for aliases (perhaps L).

share|improve this answer
    
Is there a way to make an action that takes effect when doing a drag/drop from one folder to another while holding down something like the option key which provides the destination folder so the hard link could be created directly in the new directory? –  Michael Aug 3 at 0:29
    
@Michael that would probably do best as a question of its own and not a comment on this answer. –  Daniel Lawson Aug 5 at 1:46

There's no way to do this in Finder.app itself. However, if your goal is just to avoid typing the commands into Terminal.app then you could use Automator.app to create a workflow to do the commands for you.

share|improve this answer

Yes, indirectly.

Automator let's you make services that run any shell script and also can ask you for a path to the destination for the hard link (since it won't be in the same location as the original presumably). I suppose you could default the link location somewhere like a desktop too.

Just add a step to pop up a dialog to enter or otherwise choose the destination and pass that to your ln command.

share|improve this answer

Nice solution provided by Daniel, but I suggest replacing his script code by the one below which preserves the file type.

for f in "$@"
do  
  ln "$f" "Plink-$(basename "$f")"
done
share|improve this answer
    
What does "not destructive for file type" mean? –  Mark Oct 11 at 14:15
    
I followed the patern that the Finder's "make alias" command uses. You can, of course, change the naming convention however you see fit. –  Daniel Lawson Oct 11 at 14:46

I actually wanted the link term in the rename with the extension preserved otherwise finder wouldn't recognize the filetype.

so I used Daniel's Answer(thanks for that) and changed it a bit

for f in "$@"; do
    extension="${filename##*.}"
    filename="${f%.*}"  
    ln "$f" "$filename link.$extension" 
done
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.