0

suppose file name is file1 in home dir how can create their hard links on different directory I tried :

ln -t file1 filehardlink > / home/dir2
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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