linux ln 硬链接_带有ln命令Linux Unix符号软链接和硬链接

linux ln 硬链接

linux ln 硬链接

Linux provides different ways to work with files. Generally, a file is accessed directly. But there are some situations to create links that are used as original file.

Linux提供了多种处理文件的方式。 通常,直接访问文件。 但是在某些情况下,可以创建用作原始文件的链接。

链接类型 (Link Types)

As we will see in the following of this tutorial there are two types of links named soft link and hard link. They are both links but their behavior are different from each other.

我们将在本教程的以下部分中看到两种类型的链接,分别称为软链接和硬链接。 它们都是链接,但是它们的行为彼此不同。

硬链接 (Hard Link)

Hard links are two-way links, where a change in the link will affect the original file and also the reverse, is true. There are some restrictions for hard links.

硬链接是双向链接,其中链接的更改会影响原始文件,反之亦然。 硬链接有一些限制。

  • Hard links can not link directories

    硬链接无法链接目录
  • Hard links can not link to other files systems than source like two separate partitions.

    硬链接不能链接到源以外的其他文件系统,例如两个单独的分区。

软链接或符号链接 (Soft or Symbolic Link)

Soft links are one way there a change in the link will not affect the source file. ln command is a Linux tool to manage symbolic links. ln becomes very useful when there is file restrictions or file name related issues.

软链接是链接更改不会影响源文件的一种方法。 ln命令是用于管理符号链接Linux工具。 当存在文件限制或文件名相关的问题时, ln变得非常有用。

ln命令语法 (ln Command Syntax)

As we see ln syntax is like below.

如我们所见,ln语法如下所示。

ln OPTION TARGET LINK_NAME
  • `OPTION` provides different behavior like a soft and hard link for the ln command.

    OPTION提供了不同的行为,例如ln命令的软链接和硬链接。
  • `TARGET` is the file or folder we want to create link.

    “ TARGET”是我们要创建链接的文件或文件夹。
  • `LINK_NAME` is the new link name and path we will create.

    “ LINK_NAME”是我们将创建的新链接名称和路径。

ln命令帮助 (ln Command Help)

We can list help information about the ln command with the --help option like below.

我们可以使用--help选项列出有关ln命令的帮助信息,如下所示。

$ ln --help
ln Command Help
ln Command Help
ln命令帮助

创建硬链接(Create Hard Link)

We can create hard links by using ln command. We do not need to provide many options. We will just provide the source and destination or hard link path. In this example, we will create a hard link named MyInput to the file named myinput.py like below.

我们可以使用ln命令创建硬链接。 我们不需要提供很多选择。 我们将只提供源和目标或硬链接路径。 在这个例子中,我们将创建一个名为硬链接MyInput的文件和名为myinput.py像下面。

$ ln myinput.py MyInput
Create Hard Link
Create Hard Link
创建硬链接

创建符号链接(Create Symbolic Link)

Linux provides a mechanism named symbolic link. It can be created a soft link like below. In other ways, we call it creating symbolic link Linux. In this example, we will create a symbolic or soft link name RealInput where it will point to the myinput.py

Linux提供了一种称为符号链接的机制。 可以如下创建一个软链接。 在其他方面,我们称其为创建符号链接Linux。 在此示例中,我们将创建一个符号或软链接名称RealInput ,它将指向myinput.py

$ ln -s myinput.py RealInput
Symbolic Link Linux
Symbolic Link Linux
符号链接Linux

We can see that symbolic link files are shown in a different color if bash coloring is enabled. It is shown that RealInput is linked to the file myinput.py with lscommand.

我们可以看到,如果启用了bash着色,则符号链接文件将以不同的颜色显示。 显示了使用ls命令将RealInput链接到文件myinput.py

LEARN MORE  Useful Linux Commands
了解更多有用Linux命令

删除符号链接(Remove Symbolic Link)

Removing symbolic links is as easy as removing a file. Rm command is used to remove the symbolic link but the original file stays without effecting this. We will remove RealInput soft link.

删除符号链接就像删除文件一样容易。 Rm命令用于删除符号链接,但原始文件将保留而不会影响此链接。 我们将删除RealInput软链接。

$ rm RealInput
 

翻译自: https://www.poftut.com/linux-unix-symbolic-soft-and-hard-links-with-ln-command/

linux ln 硬链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值