Difference between a Hard Link and Soft (Symbolic) Link
Within the Unix/Linux file system, linking lets you create file shortcuts to link one or more files. Linux provides two different linking methods (hard and soft links) which will further be explained in this tutorial.
To better understand how linking works, it may be easier to first understand the concept of inodes. Each file contains an index number called an inode. An inode (typically represented by a numerical value) is a data structure comprised of metadata information about the associated file. Linking utilizes inodes by pointing a file towards a specific inode value.

To view a file’s inode number, issue the command ls –i within the command prompt:
[Dillon@localhost Tutorial]$ ls -i
929447 example_file_1.txt
929448 example_file_2.txt
929449 example_file_3.txt
In the following example, the original file and hard linked file point to the same inode value of “101”.

[Dillon@localhost Tutorial]$ ln original_file new_hardlink_file [Dillon@localhost Tutorial]$ ls –l -rw-rw-r--. 2 Dillon Dillon 28 Dec 28 14:28 new_hardlink_file
-rw-rw-r--. 2 Dillon Dillon 28 Dec 28 14:28 original_file
A soft link is similar to the file shortcut feature which is used in Windows Operating systems. Each soft linked file contains a separate inode value that points to the original file. As similar to hard links, any changes to the data in either file is reflected in the other.
Soft links are beneficial as they can be linked across different file systems, although if the original file is deleted or moved, the soft linked file will not work correctly (called hanging link).
In the following example, the softlink points to the location of the original file. Notice that both files contain different inode values.

[Dillon@localhost Tutorial]$ ln -s original_file new_softlink_file [Dillon@localhost Tutorial]$ ls -l lrwxrwxrwx. 1 Dillon Dillon 28 Dec 28 14:32 new_softlink_file -> original_file
-rw-rw-r--. 1 Dillon Dillon 28 Dec 28 14:32 original_file
To fix a hanging link, you must first determine the original file that the soft link pointed to. Issue the command ls -l command to verify this file – the broken link will typically be indicated by red colored text. In this example, the file “original_file” has been moved which resulted in the associated soft link to become broken.
[Dillon@localhost Tutorial]$ ls -l lrwxrwxrwx. 1 Dillon Dillon 13 Dec 28 14:32 new_softlink_file - original_file
[Dillon@localhost Tutorial]$ find -name "original_file"
Folder 1/original_file
[Dillon@localhost Tutorial]$ unlink new_softlink_file [Dillon@localhost Tutorial]$ ls -l
[Dillon@localhost Tutorial]$ ln -s Folder_1/original_file new_softlink_file [Dillon@localhost Tutorial]$ ls -l
lrwxrwxrwx. 1 Dillon Dillon 25 Dec 28 15:07 new_softlink_file -> Folder_1/original_file
- Issue the ln [original filename] [link name] command to create a hard link
- Original File and Hard Linked file contain the same inode value
- Creates a mirror copy of the file
- Any changes to either original file or hard linked file are reflected in the other file
- Benefit – more flexible and remain linked if either the original or hard linked file is moved
- Negative – unable to cross different file systems
Soft Links:
- Issue the ln -s [original filename] [link name] command to create a soft link
- Similar to shortcut feature in Windows Operating system
- Original File and Hard Linked file contain different inode values
- Each soft link file points to the original file’s inode
- Any changes to either original file or soft linked file are reflected in the other file
- Benefit – soft linked file can cross different file systems
- Negative – if original file is deleted or moved, the soft link is broken (hanging link)
Difference between a Hard Link and Soft (Symbolic) Link的更多相关文章
- 转载:Linux: What’s the difference between a soft link and a hard link?
Link:https://www.moreofless.co.uk/linux-difference-soft-symbolic-link-and-hard-link/ This example sh ...
- linux shell symbolic link & soft link, symbol link, link
linux shell symbolic link symbolic link https://en.wikipedia.org/wiki/Ln_(Unix) https://stackoverflo ...
- Windows中的硬链接和软链接(hard link 和 Symbolic link)
先来了解一下Linux中的硬链接和软链接: Linux中的硬链接和软链接 Windows中的硬链接和软链接: 硬链接 从Windows NT4开始,NTFS文件系统引入了HardLink这个概念,它让 ...
- 硬链接(hard link)和符号连接(symbolic link)
inode ====== 在Linux系统中,内核为每一个新创建的文件分配一个inode,每个文件都有一个惟一的inode号,我们可以将inode简单理解成一个指针,它永远指向本文件的具体存储位置.文 ...
- What is linux symbolic link
Question :What is linux symbolic link In computing, a symbolic link (also symlink or soft link) is a ...
- Symbolic link and hard link的区别(linux)
--Symbolic link and hard link的区别(linux) --------------------------------------------------2014/06/10 ...
- Linux文件链接hard link与symbolic link
Linux中文件链接有两种方式,一种是hard link,又称为硬链接:另一种是symbolic link,又称为符号链接.要区分两者的不同要回顾Linux常用的ext2文件系统.这种文件系统使用in ...
- 出现 OSError: symbolic link privilege not held的解决方案
jupyter notebook 出现 OSError: symbolic link privilege not held问题时 以管理员方式重新打开prompt.
- ln: creating symbolic link XXXXXX : Operation not supported
ln: creating symbolic link XXXXXX : Operation not supported 转自:https://blog.csdn.net/z444_579/articl ...
随机推荐
- CART树 python小样例
决策树不断将数据切分成小数据集,直到所有目标变量完全相同,或者数据不能再切分为止,决策时是一种贪心算法,它要在给定的时间内做出最佳选择,但并不关心能否达到最优 树回归 优点:可以对复杂和非线性的数据建 ...
- python 二(续)——面向对象编程进阶
1.类的成员 2.类成员修饰符 3.类的特殊成员 在python第二课——面向对象初级,文章中介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一 ...
- Couchbase II( View And Index)
Couchbase II( View And Index) Views view的作用是从没有结构和半结构的数据对象中抽取过滤需要的信息,并生成相关的index信息,通常生成json数据. vie ...
- Unity3D_异步加载场景(进度条)
创建两个场景:现在的场景“NowScene”,要加载的场景“LoadScene”: “NowScene”如图所示,“LoadScene”任意: 创建脚本“AsyncLoadScene”,复制如下代码, ...
- mybatis maven 代码生成器(mysql)
pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...
- BZOJ1797 [Ahoi2009]Mincut 最小割 【最小割唯一性判定】
题目 A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤i≤M)条道路连接了vi,ui两个中转站,那么中转站vi可以通过该道路到达ui中转站,如果切断这条道路 ...
- 采花 flower
采花 flower 题目描述 萧芸斓是 Z 国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳 了 n 朵花,花有 c 种颜色(用整数 1- ...
- 刷题总结——飞飞侠(bzoj2143 最短路)
题目: Description 飞飞国是一个传说中的国度,国家的居民叫做飞飞侠.飞飞国是一个N×M的矩形方阵,每个格子代表一个街区.然而飞飞国是没有交通工具的.飞飞侠完全靠地面的弹射装置来移动.每个街 ...
- 通过Xode上传代码到GIthub---步骤
---恢复内容开始--- 一:打开终端,git命令进行全局配置 由于本人已经配置完成,so,直接查看配置信息 然后在本地创建一个文件夹, 然后在gitHub上创建一个代码库 在终端clone到本地创建 ...
- Reactor Cooling(ZOJ 2314)
题意: 给n个点,及m根pipe,每根pipe用来流躺液体的,单向的,每时每刻每根pipe流进来的物质要等于流出去的物质,要使得m条pipe组成一个循环体,里面流躺物质. 并且满足每根pipe一定的流 ...