I had a file with symbolic link

link -> original_file


I mistakenly ran unlink command with original_file

Now the original file is missing and the symbolic link is broken. What to do? How to recover the original file?

  • 7
    original_file can be, of course, recover from a backup. – Archemar May 10 '16 at 15:33
  • 1
    So that means that file has been removed just like rm do? I thought unlink should only remove sym links – Rohail Abbas May 10 '16 at 15:38
  • 2
    @RohailAbbas Uh? I wonder why you thought that. unlink removes anything except directories and has always done so. – Gilles 'SO- stop being evil' May 10 '16 at 22:56
  • @Gilles Im new to linux. Thanks @mazs for the hard-link - inode concept :) – Rohail Abbas May 11 '16 at 7:19

As the man page specifies, the unlink command will remove a specified file :


   unlink - call the unlink function to remove the specified file

Unlink will remove hard-links and symbolic-links as well. As a file in Linux is a hard-link to an inode, if a regular file is specified as a parameter, this hard-link will be removed, and if the file is the last hard-link to the inode of the file, then the file is kindof erased.

| improve this answer | |

Depending on the file system you use, you may still be able to recover the deleted file. There are plenty of tools for ext2, and several tools for more complex ext3 and ext4. For example, you could try

extundelete /dev/sdaX --restore-directory someDirectory

This will restore all files found on the partition. If you happen to know the exact inode your file was linked to, you can restore just that file.

| improve this answer | |

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.