I made a hard linked file in terminal by command:
ln somefile somefile_h
and used it for fun. Now I faced a question that how can I delete the link between these two files and use it separately?
Anybody know?

- 141
-
1@dessert I don't think this is a dupe. The OP here is talking about hard links, not symbolic links and is (understandably) confused about what those are. – terdon Oct 25 '19 at 15:56
-
Breaking a hard-link in-place? may help. Also related, albeit more broadly: What is the difference between a hard link and a symbolic link?, Are hard links equivalent to Windows shortcuts?, How do I delete a hard link?; What is the difference between symbolic and hard links?, What is the difference between a hard link and a file? – Eliah Kagan Oct 25 '19 at 17:44
2 Answers
To create independent files, do the following (assuming somefile
is in your current directory):
cp somefile temp_somefile
rm somefile
mv temp_somefile somefile
This will create an identical file somefile
, that is not anymore linked to somefile_h
. No knowledge of where the linked file exists on your file system is required with this approach.
If you know where the linked file is, then it is shorter to delete that linked file and next make a regular copy of the (previously linked) file under the same file name:
rm <path>/somefile_h
cp somefile <path>/somefile_h
A way to achieve this with a cp
single command was provided by user bac0n:
cp --remove-destination somefile <path>/somefile_h
Here, the destination (linked) file is deleted before making a copy. Thus, the copy becomes a "new", regular file that is not anymore linked to the source file.

- 88,010
Hard linked file is like name pointing to same inode.
To remove your hardlink, just
rm linked_name
That doesn't affect your original filename and data in disk, there is a inode reference counter that increments on linking and decrements when you unlink instance. When counter reaches zero, inode is removed and space is marked free.
To make copy, use cp
and for link, use ln

- 1,004
- 8
- 11