0

Suppose the file name is file1 in the home directory. How can I create a hard link in a different directory? I tried :

ln -t file1 filehardlink > / home/dir2

2 Answers 2

4
ln file1 /home/dir2/

This would create a hard link (i.e. an additional name) in /home/dir2 for the file called file1 in the current directory. The name of the file in /home/dir2 will also be file1.

ln file1 /home/dir2/filehardlink

This would do the same as the above, but the new name of the file under /home/dir2 would be filehardlink. Note that there is no reason to distinguish the two names of the file by saying that one is a hard link to the other. All names are hard links to files, and there is absolutely no difference between the names file1 and filehardlink after the above operation.

This will require that the current directory and /home/dir2 are residing on the same filesystem as hard links can't span filesystems.

1

You can use command ln in such way:

ln /path/to/original_file /path2/to/linked_file

But be aware hardlinks by definition can exist only in same filesystem

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.