Remove a symlink to a directory

前端 未结 11 988
情深已故
情深已故 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:59

    Assuming it actually is a symlink,

    $ rm -d symlink
    

    It should figure it out, but since it can't we enable the latent code that was intended for another case that no longer exists but happens to do the right thing here.

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

    Assuming your setup is something like: ln -s /mnt/bar ~/foo, then you should be able to do a rm foo with no problem. If you can't, make sure you are the owner of the foo and have permission to write/execute the file. Removing foo will not touch bar, unless you do it recursively.

    0 讨论(0)
  • 2020-12-02 04:00

    rm should remove the symbolic link.

    skrall@skrall-desktop:~$ mkdir bar
    skrall@skrall-desktop:~$ ln -s bar foo
    skrall@skrall-desktop:~$ ls -l foo
    lrwxrwxrwx 1 skrall skrall 3 2008-10-16 16:22 foo -> bar
    skrall@skrall-desktop:~$ rm foo
    skrall@skrall-desktop:~$ ls -l foo
    ls: cannot access foo: No such file or directory
    skrall@skrall-desktop:~$ ls -l bar
    total 0
    skrall@skrall-desktop:~$ 
    
    0 讨论(0)
  • 2020-12-02 04:08

    Use rm symlinkname but do not include a forward slash at the end (do not use: rm symlinkname/). You will then be asked if you want to remove the symlink, y to answer yes.

    0 讨论(0)
  • 2020-12-02 04:08

    On CentOS, just run rm linkname and it will ask to "remove symbolic link?". Type Y and Enter, the link will be gone and the directory be safe.

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