Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1172566
  • 博文数量: 181
  • 博客积分: 4968
  • 博客等级: 上校
  • 技术积分: 1867
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-13 21:52
文章分类

全部博文(181)

文章存档

2015年(2)

2013年(6)

2012年(22)

2011年(41)

2010年(27)

2009年(51)

2008年(32)

我的朋友

分类: LINUX

2008-12-31 01:00:49

硬链接时,新增加一个 inode 链接到文件的数据块;而符号链接时,只是新创建了一个文件,它指向所链接的文件。
 
# 1. 使用文件 /oradata2/yct/rc.local 进行测试
[oracle@sbdatabase yct]$ pwd
/oradata2/yct
[oracle@sbdatabase yct]$ ll
total 4
-rwxr-xr-x 1 oracle dba 220 Dec  9 16:30 rc.local
[oracle@sbdatabase yct]$ more rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
 
touch /var/lock/subsys/local
 
# 2. 进行硬链接,inode 数增加
[oracle@sbdatabase yct]$ ln rc.local rc.local_hard.ln
[oracle@sbdatabase yct]$ ll
total 8
-rwxr-xr-x 2 oracle dba 220 Dec  9 16:30 rc.local
-rwxr-xr-x 2 oracle dba 220 Dec  9 16:30 rc.local_hard.ln
 
# 3. 进行符号链接,inode数并没有增加
[oracle@sbdatabase yct]$ ln -s rc.local rc.local_soft.ln
[oracle@sbdatabase yct]$ ll
total 8
-rwxr-xr-x 2 oracle dba 220 Dec  9 16:30 rc.local
-rwxr-xr-x 2 oracle dba 220 Dec  9 16:30 rc.local_hard.ln
lrwxrwxrwx 1 oracle dba   8 Dec  9 17:03 rc.local_soft.ln -> rc.local
 
# 4. 删除原文件后,硬链接仍可用,而符号链接失效。
[oracle@sbdatabase yct]$ rm rc.local
[oracle@sbdatabase yct]$ ll
total 4
-rwxr-xr-x 1 oracle dba 220 Dec  9 16:30 rc.local_hard.ln
lrwxrwxrwx 1 oracle dba   8 Dec  9 17:03 rc.local_soft.ln -> rc.local
[oracle@sbdatabase yct]$ more rc.local_hard.ln
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
 
touch /var/lock/subsys/local
[oracle@sbdatabase yct]$ more rc.local_soft.ln
rc.local_soft.ln: No such file or directory
 
# 5. 硬链接不能链接目录
[oracle@sbdatabase yct]$ rm -r *
[oracle@sbdatabase yct]$ ll
total 0
[oracle@sbdatabase yct]$ mkdir t1
[oracle@sbdatabase yct]$ ln t1 t1_hard.ln
ln: `t1': hard link not allowed for directory
[oracle@sbdatabase yct]$ ln -s t1 t1_soft.ln
[oracle@sbdatabase yct]$ ll
total 4
drwxr-xr-x 2 oracle dba 4096 Dec  9 17:09 t1
lrwxrwxrwx 1 oracle dba    2 Dec  9 17:09 t1_soft.ln -> t1
[oracle@sbdatabase yct]$
阅读(1593) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-01-06 21:08:49

个人觉得“inode数增加或没有增加”的说法不妥当,ls第二列里面的数字是引用计数,也就是说2表示这个inode被两个文件共享。就文件系统来说,硬链接是不增加inode数,只是让不同文件的目录项中inode号指向同一个inode,而符号链接是创建了一个新的inode的。

samon_fu2009-01-04 17:57:17

感觉有2点能完善下就好了: 1、硬链接与软连接的用途(揉合产生的历史原因来讲会更好) 2、做链接有个致命的点需要提到,就是交叉链接

chinaunix网友2009-01-03 21:28:21

关键的一点,ln创建的文件inode和原文件是一样的,这一点居然都没有提到 ls -li 看一下好了

chinaunix网友2008-12-31 15:18:40

您好,我叫Susie,是猎头公司的顾问,现在有一个MNC的关于Linux开发的职位, 如果您感兴趣的话,欢迎与我联系。我的邮箱地址是susie.ren@globalassociates.com,非常感谢!