hard link vs soft link
2016-05-25 11:38
197 查看
Inodes are associated with precisely one directory entry at a time. However, with hard links it is possible to associate multiple directory
entries with a single inode. To create a hard link use ln command as follows:
Above commands create a link to file1. Symbolic links refer to:
A symbolic path indicating the abstract location of another file.
Hard links refer to:
The specific location of physical data.
Hard links cannot link directories.
Cannot cross file system boundaries.
Soft or symbolic links are just like hard links. It allows to associate multiple filenames with a single file. However, symbolic links allows:
To create links between directories.
Can cross file system boundaries.
These links behave differently when the source of the link is moved or removed.
Symbolic links are not updated.
Hard links always refer to the source, even if moved or removed.
You can create symbolic link with ln command:
Above command will create a symbolic link to file1.txt.
Let us create a directory called foo, enter:
Copy /etc/resolv.conf file, enter:
View inode number, enter:
Sample output:
Now create soft link to resolv.conf, enter:
Sample output:
The reference count of the directory has not changed (total 152). Our symbolic (soft) link is stored in a different inode than the text file (1048602). The information stored in resolv.conf is accessible through the alink.conf file. If we delete the text file
resolv.conf, alink.conf becomes a broken link and our data is lost:
If alink.conf was a hard link, our data would still be accessible through alink.conf. Also, if you delete the soft link itself, the data would still be there. Read man page of ln for more information.
entries with a single inode. To create a hard link use ln command as follows:
# ln /root/file1 /root/file2 # ls -l
Above commands create a link to file1. Symbolic links refer to:
A symbolic path indicating the abstract location of another file.
Hard links refer to:
The specific location of physical data.
Hard link vs. Soft link in Linux or UNIX
Hard links cannot link directories.Cannot cross file system boundaries.
Soft or symbolic links are just like hard links. It allows to associate multiple filenames with a single file. However, symbolic links allows:
To create links between directories.
Can cross file system boundaries.
These links behave differently when the source of the link is moved or removed.
Symbolic links are not updated.
Hard links always refer to the source, even if moved or removed.
How do I create symbolic link?
You can create symbolic link with ln command:$ ln -s /path/to/file1.txt /path/to/file2.txt $ ls -ali
Above command will create a symbolic link to file1.txt.
Task: Symbolic link creation and deletion
Let us create a directory called foo, enter:$ mkdir foo $ cd foo
Copy /etc/resolv.conf file, enter:
$ cp /etc/resolv.conf .
View inode number, enter:
$ ls -ali
Sample output:
total 152 1048600 drwxr-xr-x 2 vivek vivek 4096 2008-12-09 20:19 . 1015809 drwxrwxrwt 220 root root 143360 2008-12-09 20:19 .. 1048601 -rwxr-xr-x 1 vivek vivek 129 2008-12-09 20:19 resolv.conf
Now create soft link to resolv.conf, enter:
$ ln -s resolv.conf alink.conf $ ls -ali
Sample output:
total 152 1048600 drwxr-xr-x 2 vivek vivek 4096 2008-12-09 20:24 . 1015809 drwxrwxrwt 220 root root 143360 2008-12-09 20:19 .. 1048602 lrwxrwxrwx 1 vivek vivek 11 2008-12-09 20:24 alink.conf -> resolv.conf 1048601 -rwxr-xr-x 1 vivek vivek 129 2008-12-09 20:19 resolv.conf
The reference count of the directory has not changed (total 152). Our symbolic (soft) link is stored in a different inode than the text file (1048602). The information stored in resolv.conf is accessible through the alink.conf file. If we delete the text file
resolv.conf, alink.conf becomes a broken link and our data is lost:
$ rm resolv.conf $ ls -ali
If alink.conf was a hard link, our data would still be accessible through alink.conf. Also, if you delete the soft link itself, the data would still be there. Read man page of ln for more information.
相关文章推荐
- Android 使用第三方SDK—友盟实现分享功能
- Python2学习笔记(2)
- vim的最最最基本操作
- MySQL如何选择float, double, decimal
- MongoDB JAVA API Filters
- C++小里程
- SpringMVC Controller写法
- Ajax-基础篇
- Android Navigation TabBar控件实现多彩标签栏
- java.lang.OutOfMemoryError: PermGen space及其解决方法
- iOS上线流程
- 正则表达式
- 使用JMeter对Tomcat进行压力测试与Tomcat性能调优
- windows2008r2的时间同步小结
- linux下关闭网络命令
- 桌面显卡天梯图和桌面cpu天梯图
- Active-MQ的安装
- C/C++ const 用法
- 简单理解RemoteView
- 零基础易语言入门教程(四)之数据类型