How Do I Remove a Hard Link in Linux?
Contents

4 Answers. You can delete it with rm as usual: rm NameOfFile . Note that with hard links there is no distinction between “the original file” and “the link to the file”: you just have two names for the same file, and deleting just one of the names will not delete the other.

If you delete the ‘my-hard-link’ of a hard link, the remaining files pointing to that same space (inode) in the hard drive will still contain the data stored on the hard drive.

Use the ln command to create additional hard links to an existing file (but not to a directory, even though the system sets up . and .. as hard links). Listing 1 shows how to create a directory containing two files and a subdirectory with two hard links to file1, one in the same directory and one in the subdirectory.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest