命令行 上下箭头符号

Symbolic links allow you to links files and directories to other files and directories. They go by many names including symlinks, shell links, soft links, shortcuts, and aliases. At a glance, a symbolic link looks like just a file or directory, but when you interact with them, they will actually interact with the target at the other end. Think of them like worm holes for your file system.

使用符号链接可以将文件和目录链接到其他文件和目录。 它们有很多名称,包括符号链接,shell链接,软链接,快捷方式和别名。 乍一看,符号链接看起来就像一个文件或目录,但是当您与它们交互时,它们实际上将与另一端的目标交互。 将它们视为文件系统的蠕虫Kong。

入门 (Getting started)

The system call necessary to create symbolic links tends to be readily available on Unix-like and POSIX-compliant operating systems. The command we’ll be using to create the links is the ln command.

创建符号链接所需的系统调用通常可以在类似Unix且兼容POSIX的操作系统上使用。 我们将用来创建链接的命令是ln命令。

You’re welcome to use the files on your system to mess around with, but I thought it would be nice to provide a few lines of code to setup an environment for following along with this post:

欢迎您使用系统上的文件来解决问题,但是我认为最好提供几行代码来设置一个环境,以供后续工作:

$ mkdir -p /tmp/symlinks/{one,two}
$ cd /tmp/symlinks
$ echo "one" > ./one/one.txt
$ echo "two" > ./two/two.txt

If you were to run tree, it should look like this:

如果要运行tree ,则应如下所示:

$ tree
.
├── one
│   └── one.txt
└── two└── two.txt2 directories, 2 files

Perfect, let’s get to linking!

完美,让我们开始链接!

硬连结 (Hard linking)

By default, the ln command will make hard links instead of symbolic, or soft, links.

默认情况下, ln命令将建立硬链接,而不是符号链接或软链接。

To ensure that we’re creating symbolic links, we’ll want to pass the -s or --symbolic argument to the ln command.

为确保创建符号链接,我们将-s--symbolic参数传递给ln命令。

What’s a hard link anyway?

硬链接到底是什么?

Hard links link directly to the inode where the item resides on the disk, instead of acting as a pointer to the original file, the way symbolic links do. What you end up with is a copy of the original and any changes to the original will not be reflected.

硬链接直接链接到项目在磁盘上所在的索引节点,而不是像符号链接那样充当指向原始文件的指针。 您最终得到的是原件的副本,对原件的任何更改都不会反映出来。

Hard links serve their purpose in the world, but should be avoided when linking inside of of a git repository as they cause a ton of confusion.

硬链接在世界上达到了他们的目的,但是在git存储库内部进行链接时应避免使用硬链接,因为它们会引起很多混乱。

From my own experience, I’m always using symbolic links, but never hard links. As I write this, I’m wondering why I have yet to alias ln to ln -s to save a few keystrokes:

根据我自己的经验,我一直使用符号链接,但从未使用硬链接。 在撰写本文时,我想知道为什么我还没有将ln别名为ln -s来保存一些击键:

alias ls="ln -s"

符号链接 (Symbolic linking)

As mentioned, symbolic linking is effectively like creating a file that contains the target’s filename and path.

如前所述,符号链接实际上就像创建一个包含目标文件名和路径的文件。

Because it’s simply a reference to the original file, any changes that are made to the original will be immediately available via the symbolic link.

因为它只是对原始文件的引用,所以对原始文件所做的任何更改都可以通过符号链接立即获得。

Some of my favorite uses for symbolic links are to create local directories in my home directory that point to files being synchronized by Dropbox or to link current to the latest build of a project in a directory that is dynamically named and includes a date and time.

我最喜欢的符号链接用法是在我的主目录中创建本地目录,该目录指向Dropbox正在同步的文件,或者将current目录链接到动态命名的目录(包括日期和时间)中的项目的最新版本。

Given the files we created earlier in the getting started section, let’s go ahead and try linking the one directory to the three directory:

给定我们在入门一节中前面创建的文件,让我们继续尝试将one目录链接到three目录:

$ ln -s one three

Now we should have 3 directories, one of which is pointing back to another. To see things in more detail, we can use the ls command:

现在我们应该有3个目录,其中一个指向另一个。 要更详细地了解事物,我们可以使用ls命令:

$ ls
one/  three@  two/

Notice the @ symbol? That indicates that the file is a symbolic link!

注意@符号吗? 这表明该文件是符号链接!

For even greater detail, we can pass in the -l argument and see where the symbolic link is actually pointed:

有关更多详细信息,我们可以传入-l参数,看看符号链接实际指向的位置:

$ ls -l
total 0
drwxr-xr-x 2 josh josh 60 Sep 13 17:18 one/
lrwxrwxrwx 1 josh josh  3 Sep 13 17:34 three -> one/
drwxr-xr-x 2 josh josh 60 Sep 13 17:18 two/

As expected, the three link is pointed to the one directory.

不出所料,这three链接指向one目录。

Symbolic links can also contain symbolic links, so we could go ahead and link the one.txt file from three to the two directory:

符号链接也可以包含符号链接,因此我们可以将one.txt文件从three链接到two目录:

$ ln -s three/one.txt two/one.txt

We should now have a file named one.txt inside of the two directory. Depending on your terminal configuration, this file very well may be blinking red.

现在,我们应该在two目录中有一个名为one.txt的文件。 根据您的终端配置,此文件可能会闪烁红色。

Even though the symbolic link was created, the way we specified the path was relative and thus, the link is broken because the two directory doesn’t contain a three directory with the one.txt file in it.

即使创建了符号链接,我们指定路径的方式也是相对的,因此该链接已断开,因为two目录中没有包含带有one.txt文件的three目录。

Fortunately, we can remedy this situation but telling ln to create the symbolic link relative to the link location using the -r or --relative argument.

幸运的是,我们可以纠正这种情况,但可以告诉ln使用-r--relative参数创建相对于链接位置的符号链接。

Not so fast though, because the symbolic link already exists, we can’t overwrite it without passing in the -f or --force argument as well:

但是速度不是很快,因为符号链接已经存在,所以我们也不能不传递-f--force参数就覆盖它:

$ ln -srf three/one.txt two/one.txt

Great! We now have two/one.txt which was linked to three/one.txt which is a link to one/one.txt.

大! 现在,我们有two/one.txt链接到three/one.txt ,后者是一个链接到one/one.txt

Phew, what a mouthful.

ew,真是满嘴。

Funny enough, your file system thinks it’s a mouthful as well. When we run tree, the link target being shown is actually that of our original location and not to the link itself:

有趣的是,您的文件系统也认为这很麻烦。 当我们运行tree ,显示的链接目标实际上是我们原始位置的目标,而不是链接本身:

$ tree
.
├── one
│   └── one.txt
├── three -> one
└── two├── one.txt -> ../one/one.txt└── two.txt3 directories, 3 files

Now that things are linked up nice, we can really see how symbolic links work by messing with the file contents.

现在事情已经很好地链接了,我们可以通过弄乱文件内容来真正了解符号链接的工作方式。

Here’s what all of our one.txt files look like right now:

这是我们所有的one.txt文件现在的样子:

$ cat {one,two,three}/one.txt
one
one
one

And if we were to update the contents of the original file and check again:

如果我们要更新原始文件的内容并再次检查:

$ echo "1. One" > one/one.txt
$ cat {one,two,three}/one.txt
1. One
1. One
1. One

Or even if we changed the contents via one of the symbolic links:

或者即使我们通过其中一个符号链接更改了内容:

$ echo "One and done" > three/one.txt
$ cat {one,two,three}/one.txt
One and done
One and done
One and done

Because symbolic links are simply pointers to files, any change we make, to the original file or the symbolic links will be immediately reflected in the original file or any symbolic links to the file.

因为符号链接只是指向文件的指针,所以我们对原始文件或符号链接所做的任何更改都将立即反映在原始文件或指向该文件的任何符号链接中。

结论 (Conclusion)

I hope you enjoyed this introduction to symbolic links. I do want to leave you with one word of caution though.

希望您喜欢符号链接的介绍。 不过,我确实想提醒您。

While linking is pretty great, and can make your life a ton easier, keep in mind that if you were to move or delete the original file or directory, all of your existing symbolic links pointed to it will become broken. There’s no automatic updating in that scenario.

虽然链接非常棒,并且可以使您的生活更轻松,但是请记住,如果要移动或删除原始文件或目录,则指向该文件或目录的所有现有符号链接都将断开。 在这种情况下,没有自动更新。

Hopefully this small short coming doesn’t scare you off from using this powerful command-line functionality!

希望这个短暂的机会不会吓到您使用此强大的命令行功能!

翻译自: https://www.digitalocean.com/community/tutorials/workflow-symbolic-links

命令行 上下箭头符号

命令行 上下箭头符号_命令行基础知识:符号链接相关推荐

  1. Linux命令中的箭头符号总结

    > 左边的内容重定向到右边的文件 会覆盖右边的文件内容 示例1: echo hello > test.txt # 输出hello到标准输出并重定向到test.txt文件 # 如果test. ...

  2. mysql 算子 谓词_[SQL] SQL 基础知识梳理(六)- 函数、谓词、CASE 表达式

    SQL 基础知识梳理(六)-  函数.谓词.CASE 表达式 目录 函数 谓词 CASE 表达式 一.函数 1.函数:输入某一值得到相应输出结果的功能,输入值称为"参数",输出值称 ...

  3. kettle对字符串去除空格_整理|ABAP基础知识二:常用字符串处理

    常用字符串处理 上一期整理了ABAP的数据类型和定义,今天我们整理一下开发过程中常见的字符串处理命令.虽然说这些基础知识对于已经熟练使用Ctrl c + Ctrl v的资深码农来说过于简单.但是对于一 ...

  4. 电脑的基础知识_电脑的基础知识大全,你确定都知道?

    电脑的基础知识大全,你确定都知道? 一.软件系统 软件系统包括:操作系统.应用软件等.应用软件中电脑行业的管理软件,IT电脑行业的发展必备利器,电脑行业的erp软件. 二.硬件系统 硬件系统包括:机箱 ...

  5. php+大于的特殊符号,CSS_网页制作基础知识:html特殊符号,一些特殊符(如小于号和大于 - phpStudy...

    一些特殊符(如小于号和大于号)经常用在html代码里面.为了显示这些特殊字符,你必须在代码里面输入html实际存在的符号.比如,显示小于号( 用特殊符号而不用图片的好处 1.它下载更快,因为是基于字体 ...

  6. 有关python方面的论文_有关python基础知识的文章推荐5篇

    一.变量命名规则1.变量名只能是字母.数字.下划线的任意组合2.变量名不能以数字开头3.一些保留字段不能作为自定义变量名4变量名需要有明确含义,如保存名字的变量,最好定义为name之类的变量名二.字符 ...

  7. 命令行执行java程序_命令行执行

    每当您旅行到一个居民说不同寻常的母语的国家时,您都可能会用一些基本的生存短语武装自己,例如"这要花多少钱?","这是哪种肉?"和"哪里在洗手间吗?&q ...

  8. 命令行编译java项目_命令行编译运行java工程(转)

    平时建立Java工程都是借助eclipse或intellij这些ide编辑器来构建,对于java工程的实际编译执行原理,从未了解过.作为一个曾经的C++程序员,对于源码刨根问底的那份执着从未丢过.于是 ...

  9. 命令方块召唤别墅指令_命令方块其实不难玩!

    #新作者扶植计划 第二期# 大家好,是我指令师. 想必各位我的世界玩家都遇到过一个问题.生存创造都已经玩的如火纯青了,但想向我的世界的高阶玩法前进---指令,但却不知道指令该如何使用,如何操作和操作格 ...

最新文章

  1. 机器学习的出现,是否意味着“古典科学”的过时?
  2. 捷报!又一名HIV感染者被治愈,干细胞移植再次立功
  3. 枚举 ---- B. Power Sequence[Codeforces Round #666 (Div. 2)][暴力]
  4. Evaluation of hybrid and non-hybrid methods for de novo assembly of nanopore reads
  5. 1.14 梯度检验应用的注意事项-深度学习第二课《改善深层神经网络》-Stanford吴恩达教授
  6. 计算机网络-基本概念(10)【传输层】TCP运输连接管理
  7. 学习MongoDB 十一: MongoDB聚合(Aggregation Pipeline基础篇上)(三)
  8. SAP云平台CloudFoundry上部署了一个应用的技术明细
  9. 基于VUE+TS中引用ECharts的中国地图和世界地图密度表
  10. Jenkins通过FTP上传站点太多文件导致太慢且不稳定,切换为压包上传再解压的思路(asp.net)...
  11. 小学认识计算机说课ppt,《认识计算机》说课稿.ppt
  12. 软件工程期末笔记整理
  13. 盈科律师事务所高级合伙人刘晓雪:锤子科技已举步维艰
  14. html页面设计扁平化,35个扁平化网站设计灵感
  15. vue+uniapp疫苗预约接种系统 微信小程序
  16. CocoaPods安装出现的错误
  17. LUBANSO硬件钱包冷知识,逻辑与查询
  18. 信息安全服务资质(CCRC)简介
  19. 2021年安全员-C证考试题及安全员-C证考试内容
  20. designs\economics建模-读书笔记

热门文章

  1. html5 触摸 滚动,html5的触摸事件
  2. oracle 日期函数(reprint)
  3. airtest学习笔记
  4. GeoServer地图开发解决方案
  5. Chrome批量打开多个网站
  6. 中国水环境治理行业投融资分析及“十四五”规划建议报告2022~2028年
  7. 流浪猫狗救助平台(基于SSM的毕业设计)
  8. 亚美尼亚副总理代表团造访清微智能
  9. 读后感---图像分割的新理论和新方法
  10. 便捷的刷脸支付彻底颠覆扫码支付方式