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?
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?
To create independent files, do the following (assuming
somefile
is in your current directory):This will create an identical file
somefile
, that is not anymore linked tosomefile_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:
A way to achieve this with a
cp
single command was provided by user bac0n: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.
Hard linked file is like name pointing to same inode.
To remove your hardlink, just
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, useln