如何在Linux中删除符号链接?

本文介绍了在Linux中管理符号链接的方法,包括列出、删除符号链接以及解决权限问题。通过`ls -l`命令可以查看现有链接,`rm`或`unlink`命令用于删除符号链接,如果遇到权限问题,可以使用`sudo`增强权限。同时,硬链接的删除也可用相同命令完成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
List Symbolic Links
List Symbolic Links
列出符号链接

删除符号链接(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 unlinkwhich 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
LEARN MORE  What Does "rm -rf" Command Do In Linux?
了解更多信息“ rm -rf”命令在Linux中做什么?

翻译自: https://www.poftut.com/remove-symbolic-links-linux/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值