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 ...
随机推荐
- HashMap 简介
HashMap 前置条件 了解数组 了解链表 jdk version: 1.8 个人分3步来了解HashMap 通过数据结构图 通过为了完成这样的数据结构我们该怎么做 HashMap 实际put方法源 ...
- 图文教程:为认证考试搭建Hyper-V家庭实验室
[TechTarget中国原创] 在过去20年里,我已经帮助成千上万人准备他们的IT认证考试.虽然有很多方法通过技术来获得经验,组建一个Hyper-V家庭实验室是个利用不同应用程序来获得经验的廉价并有 ...
- 我给女朋友讲编程CSS系列(2)- CSS语法、3大选择器、选择器优先级
首先看一下使用Css设置h1标签字体颜色和大小的例子,效果图如下: 新建一个网页test.html,然后复制粘贴下面的内容: <html> <head> <style t ...
- plsql 编程基础
分支 declare --声明变量 a ); b ); c ); begin --开始 a := '小明'; dbms_output.put_line(a); b :; c :; if b > ...
- ci日志记录
log_message($level, $message) 参数: $level (string) -- Log level: 'error', 'debug' or 'info' $message ...
- 【bzoj2179】FFT快速傅立叶 FFT
题目描述 给出两个n位10进制整数x和y,你需要计算x*y. 输入 第一行一个正整数n. 第二行描述一个位数为n的正整数x. 第三行描述一个位数为n的正整数y. 输出 输出一行,即x*y的结果. 样例 ...
- Sum of Squares of the Occurrence Counts解题报告(后缀自动机+LinkCutTree+线段树思想)
题目描述 给定字符串\(S(|S|\le10^5)\),对其每个前缀求出如下的统计量: 对该字符串中的所有子串,统计其出现的次数,求其平方和. Sample Input: aaa Sample Out ...
- 编程风格——UNIX 高手的 10 个习惯
引言 当您经常使用某个系统时,往往会陷入某种固定的使用模式.有时,您没有养成以尽可能最好的方式做事的习惯.有时,您的不良习惯甚至会导致出现混乱.纠正此类缺点的最佳方法之一,就是有意识地采用抵制这些坏习 ...
- 各种 Python 实现的简单介绍与比较
当谈到Python时,一般指的是CPython.但Python实际上是一门语言规范,只是定义了Python这门语言应该具备哪些语言要素,应当能完成什么样的任务.这种语言规范可以用不同的方式实现,可以用 ...
- nodeJS学习(10) --- 事件模块
转载:http://www.cnblogs.com/zhongweiv/p/nodejs_events.html 目录 简介及资料 事件常用函数及使用 emitter.on(event, listen ...