Symbolic links provides practical solutions file name or path related problems. Symbolic links will create same file or folder with different name and path. In some situations this may cause problem and we have to remove and delete symbolic link.
符号链接提供了实用的解决方案,文件名或路径相关的问题。 符号链接将使用不同的名称和路径创建相同的文件或文件夹。 在某些情况下,这可能会导致问题,我们必须删除和删除符号链接。
列出符号链接 (List Symbolic Links)
We can start by listing existing links especially symbolic links with ls
command like below. Symbolic links provide some redirect to the source file like symbolic link RealInput
.
我们可以通过如下所示的ls
命令首先列出现有链接,尤其是符号链接。 符号链接提供了一些到源文件的重定向,例如符号链接RealInput
。
$ ls -lh

删除符号链接(Remove Symbolic Links)
There are different ways to remove symbolic link. We can just issue rm
command to the link file. In this example we will remote link named RealInput
.
有多种方法可以删除符号链接。 我们可以向链接文件发出rm
命令。 在此示例中,我们将名为RealInput
远程链接。
$ rm RealInput
使用unlink命令删除 (Remove with unlink Command)
As we use ln
command which is shortcut for link we have also command named unlink
which can unlink given links. In this example we can remove RealInput
like below. unlink
command is an alias for rm
command.
当我们使用ln
命令(它是链接的快捷方式)时,我们还使用了名为unlink
命令,该命令可以取消链接给定的链接。 在此示例中,我们可以删除RealInput
如下所示。 unlink
命令是rm
命令的别名。
$ unlink RealInput
使用sudo删除符号链接以解决“权限被拒绝”错误 (Remove Symbolic Links with sudo for “Permission Denied” Error)
Some symbolic links may be created by privileged user like root
. If we try to remove this links with regular or less privileged user we will get an error like permission denied
. So in order to remove this symbolic links we need to provide sudo
command at the beginning of the command like below.
一些符号链接可能由root
用户等特权用户创建。 如果我们尝试删除普通用户或特权较少的用户的此链接,则会收到类似permission denied
的错误。 因此,为了删除此符号链接,我们需要在命令的开头提供sudo
命令,如下所示。
$ sudo rm RealInput
删除硬链接 (Remove Hard Links)
We can easily remove hard links with the same commands too.
我们也可以使用相同的命令轻松删除硬链接。
$ unlink RealInput
OR
要么
$ rm RealInput