硬链接和软连接
2015-06-16 17:05
232 查看
- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
文件用户数据块存放的是另一个文件的路径名的指向。
软链接就是一个普通文件,只是数据块内容有点特殊。
原文件和软链接的inode不同,但修改任何一个文件都会改变文件的内容。
[root@Centos6 ~]# ls -litotal 4392110 lrwxrwxrwx 1 root root 6 Jun 16 15:20 test.doc -> test.log 10060 lrwxrwxrwx 1 root root 6 Jun 16 15:20 test.log -> test.txt392109 -rw-r--r-- 1 root root 24 Jun 16 15:47 test.txt[root@Centos6 ~]# cat test.txt Address: 8.8.8.8[root@Centos6 ~]# cat test.log Address: 8.8.8.8[root@Centos6 ~]# cat test.doc Address: 8.8.8.8[root@Centos6 ~]# echo -n modified >> test.txt [root@Centos6 ~]# cat test.txt Address: 8.8.8.8modified[root@Centos6 ~]# cat test.log Address: 8.8.8.8modified[root@Centos6 ~]# cat test.doc Address: 8.8.8.8modified[root@Centos6 ~]# rm -f test.doc [root@Centos6 ~]# ls -litotal 4 10060 lrwxrwxrwx 1 root root 6 Jun 16 15:20 test.log -> test.txt392109 -rw-r--r-- 1 root root 32 Jun 16 15:50 test.txt[root@Centos6 ~]# rm -f test.txt [root@Centos6 ~]# ls -litotal 0 10060 lrwxrwxrwx lrwxrwxrwx 1 root root 6 Jun 16 15:20 test.log -> test.txt[root@Centos6 ~]# cat test.log cat: test.log: No such file or directory
test.txt为原文件
test.log为test.txt的软链接test.doc为test.log的软链接
各文件的inode不同。当修改任何一个文件时其他文件也跟着改变。当删除原文件test.txt后,test.log则变成了死链接,ls将显示为红色,并且看不到文件内容了。
- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
由于硬链接是有着相同inode号仅文件名不同的文件,因此删除一个硬链接文件并不影响其他有相同inode号的文件。
硬链接只能对文件创建,不能对目录创建。
硬链接可由link或者ln命令创建。
[u02@Centos6 ~]$ cat test.txt
Hello u02
[u02@Centos6 ~]$ ls -li
total 4
128020 -rw-r--r-- 1 u02 u02 10 Jun 16 16:51 test.txt
[u02@Centos6 ~]$ ln test.txt test01.txt
[u02@Centos6 ~]$ ls -li
total 8
128020 -rw-r--r-- 2 u02 u02 10 Jun 16 16:51 test01.txt
128020 -rw-r--r-- 2 u02 u02 10 Jun 16 16:51 test.txt
[u02@Centos6 ~]$ echo "Hello $USER" >> test01.txt
[u02@Centos6 ~]$ cat test01.txt
Hello u02
Hello u02
[u02@Centos6 ~]$ cat test.txt
Hello u02
Hello u02
[u02@Centos6 ~]$ rm -f test.txt
[u02@Centos6 ~]$ cat test01.txt
Hello u02
Hello u02
本文出自 “勿忘初心” 博客,请务必保留此出处http://winterysea.blog.51cto.com/9677346/1662412
ln -s file1 file2 # 创建文件软链接软链接,又叫符号链接。
文件用户数据块存放的是另一个文件的路径名的指向。
软链接就是一个普通文件,只是数据块内容有点特殊。
原文件和软链接的inode不同,但修改任何一个文件都会改变文件的内容。
[root@Centos6 ~]# ls -litotal 4392110 lrwxrwxrwx 1 root root 6 Jun 16 15:20 test.doc -> test.log 10060 lrwxrwxrwx 1 root root 6 Jun 16 15:20 test.log -> test.txt392109 -rw-r--r-- 1 root root 24 Jun 16 15:47 test.txt[root@Centos6 ~]# cat test.txt Address: 8.8.8.8[root@Centos6 ~]# cat test.log Address: 8.8.8.8[root@Centos6 ~]# cat test.doc Address: 8.8.8.8[root@Centos6 ~]# echo -n modified >> test.txt [root@Centos6 ~]# cat test.txt Address: 8.8.8.8modified[root@Centos6 ~]# cat test.log Address: 8.8.8.8modified[root@Centos6 ~]# cat test.doc Address: 8.8.8.8modified[root@Centos6 ~]# rm -f test.doc [root@Centos6 ~]# ls -litotal 4 10060 lrwxrwxrwx 1 root root 6 Jun 16 15:20 test.log -> test.txt392109 -rw-r--r-- 1 root root 32 Jun 16 15:50 test.txt[root@Centos6 ~]# rm -f test.txt [root@Centos6 ~]# ls -litotal 0 10060 lrwxrwxrwx lrwxrwxrwx 1 root root 6 Jun 16 15:20 test.log -> test.txt[root@Centos6 ~]# cat test.log cat: test.log: No such file or directory
test.txt为原文件
test.log为test.txt的软链接test.doc为test.log的软链接
各文件的inode不同。当修改任何一个文件时其他文件也跟着改变。当删除原文件test.txt后,test.log则变成了死链接,ls将显示为红色,并且看不到文件内容了。
- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
ln file1 file2 # 创建硬链接 link file1 file2 # 创建硬链接硬链接就是一个文件使用了多个别名(他们有共同的inode)。
由于硬链接是有着相同inode号仅文件名不同的文件,因此删除一个硬链接文件并不影响其他有相同inode号的文件。
硬链接只能对文件创建,不能对目录创建。
硬链接可由link或者ln命令创建。
[u02@Centos6 ~]$ cat test.txt
Hello u02
[u02@Centos6 ~]$ ls -li
total 4
128020 -rw-r--r-- 1 u02 u02 10 Jun 16 16:51 test.txt
[u02@Centos6 ~]$ ln test.txt test01.txt
[u02@Centos6 ~]$ ls -li
total 8
128020 -rw-r--r-- 2 u02 u02 10 Jun 16 16:51 test01.txt
128020 -rw-r--r-- 2 u02 u02 10 Jun 16 16:51 test.txt
[u02@Centos6 ~]$ echo "Hello $USER" >> test01.txt
[u02@Centos6 ~]$ cat test01.txt
Hello u02
Hello u02
[u02@Centos6 ~]$ cat test.txt
Hello u02
Hello u02
[u02@Centos6 ~]$ rm -f test.txt
[u02@Centos6 ~]$ cat test01.txt
Hello u02
Hello u02
本文出自 “勿忘初心” 博客,请务必保留此出处http://winterysea.blog.51cto.com/9677346/1662412
相关文章推荐
- Oracle数据库之事务
- 红黑树数据结构剖析
- 面试3道测试题
- Reverse a LinkedList 链表倒置
- 手把手教你写专利申请书/如何申请专利
- 离散余弦正逆变换程序
- 【SHARE】WEB前端学习资料
- 伪元素改变date类型input框的默认样式实例页面
- iOS开发经验技巧之IOS界面开发使用viewWithTag:(int)findTag方法获取界面元素
- Win10系统怎么重新开启通知中心突然发现没有了
- yum 命令的使用,及yum仓库的创建
- “WebForms UnobtrusiveValidationMode 需要“jquery”ScriptResourceMapping
- 常用js函数--个人项目总结
- wicket之实现IDataProvider接口,只查询当前页数据
- Java中JTextArea如何添加滚动条
- FireDAC 下的 Sqlite [3] - 获取数据库的基本信息
- NSProcessInfo类方法介绍
- Java初级笔记_面向对象3
- 浅析CentOS和RedHat Linux的区别
- chrome提示"安装unity web player"