Remove a symlink to a directory

前端 未结 11 987
情深已故
情深已故 2020-12-02 03:16

I have a symlink to an important directory. I want to get rid of that symlink, while keeping the directory behind it.

I tried rm and get back rm

相关标签:
11条回答
  • 2020-12-02 03:45

    use the "unlink" command and make sure not to have the / at the end

    $ unlink mySymLink
    

    unlink() deletes a name from the file system. If that name was the last link to a file and no processes have the file open the file is deleted and the space it was using is made available for reuse. If the name was the last link to a file but any processes still have the file open the file will remain in existence until the last file descriptor referring to it is closed.

    I think this may be problematic if I'm reading it correctly.

    If the name referred to a symbolic link the link is removed.

    If the name referred to a socket, fifo or device the name for it is removed but processes which have the object open may continue to use it.

    https://linux.die.net/man/2/unlink

    0 讨论(0)
  • 2020-12-02 03:46

    you can use unlink in the folder where you have created your symlink

    0 讨论(0)
  • 2020-12-02 03:48
    # this works:
    rm foo
    # versus this, which doesn't:
    rm foo/
    

    Basically, you need to tell it to delete a file, not delete a directory. I believe the difference between rm and rmdir exists because of differences in the way the C library treats each.

    At any rate, the first should work, while the second should complain about foo being a directory.

    If it doesn't work as above, then check your permissions. You need write permission to the containing directory to remove files.

    0 讨论(0)
  • 2020-12-02 03:50

    I had this problem with MinGW (actually Git Bash) running on a Windows Server. None of the above suggestions seemed to work. In the end a made a copy of the directory in case then deleted the soft link in Windows Explorer then deleted the item in the Recycle Bin. It made noises like it was deleting the files but didn't. Do make a backup though!

    0 讨论(0)
  • 2020-12-02 03:54

    I also had the same problem. So I suggest to try unlink <absolute path>.

    For example unlink ~/<USER>/<SOME OTHER DIRECTORY>/foo.

    0 讨论(0)
  • 2020-12-02 03:55

    If rm cannot remove a symlink, perhaps you need to look at the permissions on the directory that contains the symlink. To remove directory entries, you need write permission on the containing directory.

    0 讨论(0)
提交回复
热议问题