符号链接symlink

A symlink (also called a symbolic link) is a type of file in Linux that points to another file or a folder on your computer. Symlinks are similar to shortcuts in Windows.

符号链接(也称为符号链接)是Linux中一种文件类型,它指向计算机上的另一个文件或文件夹。 符号链接类似于Windows中的快捷方式。

Some people call symlinks "soft links" – a type of link in Linux/UNIX systems – as opposed to "hard links."

有人称符号链接为“软链接”(Linux / UNIX系统中的一种链接),而不是“硬链接”。

软链接和硬链接之间的区别 (Difference Between a Soft Link and a Hard Link)

Soft links are similar to shortcuts, and can point to another file or directory in any file system.

软链接类似于快捷方式,并且可以指向任何文件系统中的另一个文件或目录。

Hard links are also shortcuts for files and folders, but a hard link cannot be created for a folder or file in a different file system.

硬链接也是文件和文件夹的快捷方式,但是无法为其他文件系统中的文件夹或文件创建硬链接。

Let's look at the steps involved in creating and removing a symlink. We'll also see what broken links are, and how to delete them.

让我们看看创建和删除符号链接所涉及的步骤。 我们还将看到什么是断开的链接,以及如何删除它们。

如何创建符号链接 (How to Create a Symlink)

The syntax for creating a symlink is:

创建符号链接的语法为:

ln -s <path to the file/folder to be linked> <the path of the link to be created>

ln is the link command. The -s flag specifies that the link should be soft. -s can also be entered as -symbolic.

ln是链接命令。 -s标志指定链接应为软链接。 -s也可以作为-symbolic输入。

By default, ln command creates hard links. The next argument is path to the file (or folder) that you want to link. (That is, the file or folder you want to create a shortcut for.)

默认情况下, ln命令创建硬链接。 下一个参数是您要链接path to the file (or folder) 。 (即,您要为其创建快捷方式的文件或文件夹。)

And the last argument is the path to link itself (the shortcut).

最后一个参数是path to link自身的path to link (快捷方式)。

如何为文件创建符号链接–示例命令 (How to Create a Symlink for a File – Example Command)

ln -s /home/james/transactions.txt trans.txt

After running this command, you will be able to access the /home/james/transactions.txt with trans.txt. Any modification to trans.txt will also be reflected in the original file.

运行此命令后,您将能够使用/home/james/transactions.txt访问trans.txt 。 对trans.txt任何修改也将反映在原始文件中。

Note that this command above would create the link file trans.txt in your current directory. You can as well create a linked file in a folder link this:

请注意,上面的命令将在当前目录中创建链接文件trans.txt 。 您也可以在以下文件夹链接中创建链接文件:

ln -s /home/james/transactions.txt my-stuffs/trans.txt

There must be a directory already called "my-stuffs" in your current directory – if not the command will throw an error.

当前目录中必须已经有一个名为“ my-stuffs”的目录-如果没有,该命令将引发错误。

如何为文件夹创建符号链接–示例命令 (How to Create a Symlink for a Folder – Example Command)

Similar to above, we'd use:

与上述类似,我们将使用:

ln -s /home/james james

This would create a symlinked folder called 'james' which would contain the contents of /home/james. Any changes to this linked folder will also affect the original folder.

这将创建一个名为'james'的符号链接文件夹,其中包含/home/james的内容。 对此链接文件夹的任何更改也会影响原始文件夹。

如何删除符号链接 (How to remove a symlink)

Before you'd want to remove a symlink, you may want to confirm that a file or folder is a symlink, so that you do not tamper with your files.

在删除符号链接之前,您可能需要确认文件或文件夹是符号链接,以免篡改文件。

One way to do this is:

一种方法是:

ls -l <path-to-assumed-symlink>

Running this command on your terminal will display the properties of the file. In the result, if the first character is a small letter L ('l'), it means the file/folder is a symlink.

在终端上运行此命令将显示文件的属性。 结果,如果第一个字符是小写字母L('l'),则表示文件/文件夹是符号链接。

You'd also see an arrow (->) at the end indicating the file/folder the simlink is pointing to.

您还将在末尾看到一个箭头(->),指示simlink指向的文件/文件夹。

There are two methods to remove a symlink:

有两种方法可以删除符号链接:

如何使用取消链接删除符号链接 (How to Use Unlink to Remove a Symlink)

The syntax is:

语法为:

unlink <path-to-symlink>

This deletes the symlink if the process is successful.

如果过程成功,这将删除符号链接。

Even if the symlink is in the form of a folder, do not append '/', because Linux will assume it's a directory and unlink cannot delete directories.

即使符号链接是文件夹形式,也不要附加'/',因为Linux将假定它是目录,并且unlink无法删除目录。

如何使用rm删除符号链接 (How to use rm to Remove a Symlink )

As we've seen, a symlink is just another file or folder pointing to an original file or folder. To remove that relationship, you can remove the linked file.

如我们所见,符号链接只是指向原始文件或文件夹的另一个文件或文件夹。 要删除该关系,可以删除链接的文件。

Hence, the syntax is:

因此,语法为:

rm <path-to-symlink>

For example:

例如:

rm trans.txt
rm james

Note that trying to do rm james/ would result an error, because Linux will assume 'james/' is a directory, which would require other options like r and f. But that's not what we want. A symlink may be a folder, but we are only concerned with the name.

注意,尝试执行rm james/会导致错误,因为Linux会假设'james /'是​​目录,这将需要其他选项,例如rf 。 但这不是我们想要的。 一个符号链接可能是一个文件夹,但是我们只关心名称。

The main benefit of rm over unlink is that you can remove multiple symlinks at once, like you can with files.

rm优于unlink的主要好处是,您可以一次删除多个符号链接,就像使用文件一样。

如何查找和删除断开的链接 (How to Find and Delete Broken Links)

Broken links occur when the file or folder that a symlink points to changes path or is deleted.

当符号链接指向的文件或文件夹更改路径或被删除时,链接断开。

For example, if 'transactions.txt' moves from /home/james to /home/james/personal, the 'trans.txt' link becomes broken. Every attempt to access to the file will result in a 'No such file or directory' error. This is because the link has no contents of its own.

例如,如果'transactions.txt'从/home/james移到/home/james/personal ,则'trans.txt'链接将断开。 每次尝试访问该文件都将导致“无此文件或目录”错误。 这是因为链接没有自己的内容。

When you discover broken links, you can easily delete the file. An easy way to find broken symlinks is:

发现断开的链接时,可以轻松删除文件。 查找损坏的符号链接的简单方法是:

find /home/james -xtype l

This will list all broken symlinks in the james directory – from files to directories to sub-directories.

这将列出james目录中所有损坏的符号链接–从文件到目录再到子目录。

Passing the -delete option will delete them like so:

传递-delete选项将删除它们,如下所示:

find /home/james -xtype l -delete

结语 (Wrapping up)

Symbolic link are an interesting feature of Linux and UNIX systems.

符号链接是Linux和UNIX系统的一个有趣功能。

You can create easily accessible symlinks to refer to a file or folder that would otherwise not be convenient to access. With some practice, you will understand how these work on an intuitive level, and they will make you much more efficient at managing file systems.

您可以创建易于访问的符号链接来引用原本不方便访问的文件或文件夹。 通过一些练习,您将了解它们在直观的水平上是如何工作的,它们将使您更加有效地管理文件系统。

翻译自: https://www.freecodecamp.org/news/symlink-tutorial-in-linux-how-to-create-and-remove-a-symbolic-link/

符号链接symlink

符号链接symlink_Linux中的Symlink教程–如何创建和删除符号链接相关推荐

  1. 【java学习之路】(mysql篇)003.mysql中limit、表的创建、删除、约束

    limit limit作用 将查询结果集的一部分取出来.通常使用在分页查询当中 limit怎么用呢? 完整用法:limit startIndex, lengthstartIndex是起始下标,leng ...

  2. windows卸载qt_在Qt中,如何使用QSettings创建/修改/删除Windows注册表项/值?

    我想让我的Qt应用程序访问Windows注册表. 我做了一些研究,认为QSettings可能是要走的路. 假设我要将密钥/值放在这里:" HKEY_LOCAL_MACHINE SOFTWAR ...

  3. centos7删除符号链接_技术|在 Linux 中怎样移除(删除)符号链接

    你可能有时需要在 Linux 上创建或者删除符号链接.如果有,你知道该怎样做吗?之前你做过吗?你踩坑没有?如果你踩过坑,那没什么问题.如果还没有,别担心,我们将在这里帮助你. 使用 rm 和 unli ...

  4. linux如何删除符号链接文件夹,在Linux中怎样移除(删除)符号链接

    你可能有时需要在 Linux 上创建或者删除符号链接.如果有,你知道该怎样做吗?之前你做过吗?你踩坑没有?如果你踩过坑,那没什么问题.如果还没有,别担心,我们将在这里帮助你. 使用 rm 和 unli ...

  5. linux中mysql如何删除库,Linux环境下MySQL基础命令(2)----查看、创建、删除库和表...

    案例二,查看数据库 MySQL是一套数据库管理系统,支持运行多个库,每个库相当于一个容器,存放着许多表.数据就存在这些表中,所以查看.创建.删除库和表,在工作中必不可少. 一,查看 1,查看当前服务器 ...

  6. mysql的删除命令+linux命令大全,Linux环境下MySQL基础命令----查看、创建、删除库和表...

    案例二,查看数据库 MySQL是一套数据库管理系统,支持运行多个库,每个库相当于一个容器,存放着许多表.数据就存在这些表中,所以查看.创建.删除库和表,在工作中必不可少. 一,查看 1,查看当前服务器 ...

  7. 符号链接symlink_什么是符号链接或符号链接? 如何为Windows和Linux创建Symlink?

    符号链接symlink Symbolic Links are also known as Symlinks. Symlinks are used to create a shortcut for a ...

  8. UE5和Blender中的完整场景环境创建学习教程

    UE5和Blender中的完整环境创建–深入课程 MP4 |视频:h264,1280×720 |音频:AAC,44.1 KHz,2 Ch 语言:英语+中英文字幕(根据原英文字幕机译更准确)|时长:80 ...

  9. 计算机配件制作表格,CAD教程 中望CAD表格功能创建零件明细表

    CAD教程分享:中望CAD表格功能创建零件明细表中望CAD的最新版本中望CAD2011新增加了很多实用的功能,表格功能就是其中之一.利用中望CAD2011的表格功能可以极大地提高工作效率,今天就和大家 ...

  10. net中c#教程 如何创建、合并、下载、打印pdf文件?

    net中c#操作pdf文档,有很多插件可以使用,这里推荐其中的一个,名字叫iTextSharp,Nuget直接搜就可以找到.它能够创建与合并pdf文件.至于下载和打印pdf文件,则是通过其他方法完成的 ...

最新文章

  1. powerdesigner类图在子类中显示从父类继承来的方法
  2. Linux: debian/ubuntu下安装和使用Java 11
  3. c语言实现将两个文件复制到一个文件里_Python中复制文件的9种方法
  4. 【RecyclerView】 十、RecyclerView 数据更新 ( 增加单条数据 | 批量增加数据 )
  5. web高德maker动画_Web Maker —我如何构建一个快速的离线前端游乐场
  6. C语言之利用,函数的命名及变量的作用域实现两个数之间的交换。
  7. 生成微信所有朋友合成的头像,来自网络GitHub,
  8. 用Kotlin开发Android的Hello Kotlin!!
  9. 国家统计局:政府统计应用大数据的主要障碍
  10. 视频教程-VBScript脚本语言编程与自动化运维操作学习篇-其他
  11. 南阳oj 找球号(一)
  12. NLTK语料库nltk.download()安装失败及下载很慢的解决方法
  13. python刷阅读_Python 刷高博客阅读量
  14. 关于应用~试玩,你想知道的都在这儿了----超详细总结(上篇)
  15. 一个优秀的团队,就该这样定目标
  16. pxe高效批量网络装机--手把手教学
  17. Oracle12C--触发器(52)
  18. Ubuntu20.04桌面系统快速上手教程
  19. Django Error at /admin/ Incorrect padding
  20. 2017 php recaptcha,PHP形成谷歌reCAPTCHA

热门文章

  1. 优秀软件测试工程师必读书籍推荐
  2. 用selenium IDE编写自动化测试脚本
  3. int与byte之间的相互转化
  4. Linux查看占用内存的进程
  5. 微信小程序登陆流程详详详解 看这一篇就够了
  6. windows磁盘空间释放(二)
  7. Qt信号与槽实现方式
  8. python中求绝对值的函数_python如何取绝对值 python取绝对值方法
  9. Linux-用户操作
  10. Windows 10 自带的远程协助工具 快速助手