linux中硬链接、软链接的建立

  • 使用命令:ln
  • 命令语法:ln [-s] 源文件 目标文件
  • 说明:加上参数-s表示创建软链接,不加参数-s表示创建硬链接

使用范例:

1、创建软链接

[root@localhost test]# ln -s file1 file1.soft

查看文件属性:

[root@localhost test]# ls -l file1 file1.soft
-rw-r--r-- 1 root root 0 04-14 15:41 file1
lrwxrwxrwx 1 root root 5 04-14 15:41 file1.soft -> file1

2、创建硬链接

[root@localhost test]# ln file2 file2.hard

查看文件属性:

[root@localhost test]# ls -l file2 file2.hard
-rw-r--r-- 2 root root 0 04-14 15:42 file2
-rw-r--r-- 2 root root 0 04-14 15:42 file2.hard

软链接特点:

1、文件权限都为rwx,文件类型为l
2、有箭头指向源文件
3、软链接类似window中的快捷方式
4、源文件删除后,软链接无法再使用

硬链接特点:

1、硬链接类似(cp -p)复制功能,保留了文件的属性
2、硬链接文件与源文件同步更新
3、源文件被删除后,硬链接照样可以使用
4、硬链接不能用于目录
5、硬链接不能跨分区使用

相关的文章:

暂无评论

写评论