您的位置:首页 > 运维架构 > Linux

Linux学习笔记--ln连接文件

2008-01-15 15:59 344 查看
连接文件与Windows系统中“快捷方式”有相似,不过在Linux系统中连接文件分为
硬连接符号连接
硬连接,只是在某一目录下的块多写入一个关联数据,不会用掉incode与磁盘空间(
只有当目录的块被用完,才可能会增加一个块来完成,从而导致磁盘空间发生变化,
这样的可能性非常小)。
符号连接,我们可以理解成如Windows的快捷方式。符号连接是一个独立的新文件,
所以占inode与块。
:在ext2文件系统中,文件由文件属性块(即indoe talbe)和文件内容块两区域)

现在测试一下硬连接、符号连接的区别,
先要了解连接文件ln命令的使用:

-b like --backup but does not accept an argument

-d, -F, --directory 建立目录的硬连接。
allow the superuser to attempt to hard link directories (note: will probably
fail due to system restrictions, even for the superuser)

-s, --symbolic
make symbolic links instead of hard links 对源文件建立符号连接,而非硬连接 

实际操作:

[root@CentOS4 tmp]# du -sb ; df -i //显示当前目录占用的容量,和磁盘空间大小
36100131 .
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 917504 113524 803980 13% /
none 129323 1 129322 1% /dev/shm
[root@CentOS4 tmp]# vi test //使用vi建立一个测试文件test

Hello everyone!
~
~
~
~
"test" [New] 1L, 16C written
[root@CentOS4 tmp]# du -sb ; df -i //显示当前目录占用的容量,和磁盘空间大小
36100147 .
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 917504 113525 803979 13% /
none 129323 1 129322 1% /dev/shm
[root@CentOS4 tmp]# ln test test-hd //为test创建硬连接文件test-hd
[root@CentOS4 tmp]# du -sb ; df -i //查看建立硬件连接文件后的目录容量和磁盘大小,
这里我们可以发现,目录容量磁盘大小都没有改变。
36100147 .
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 917504 113525 803979 13% /
none 129323 1 129322 1% /dev/shm

[root@CentOS4 tmp]# ln -s test test-so //为test创建一个符号连接文件test-so文件
[root@CentOS4 tmp]# du -sb ; df -i //检查目录容量和磁盘大小的时候,我们可以发现这里
数据已经发生改变。
36100151 .
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 917504 113526 803978 13% /
none 129323 1 129322 1% /dev/shm
[root@CentOS4 tmp]# vi test-hd //这里使用vi修改test-hd文件的内容,再查看test,test-hd
,test-so是否发生改变。

Hello everyone!
hello baby!
~
~
~
~
"test-hd" 2L, 28C written
[root@CentOS4 tmp]# cat test
Hello everyone!
hello baby!
[root@CentOS4 tmp]# cat test-so
Hello everyone!
hello baby!
[root@CentOS4 tmp]# cat test-hd
Hello everyone!
hello baby!
[root@CentOS4 tmp]#

学习资料《鸟哥的Linux私房菜基础学习篇(第二版)》
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: