Linux链接文件——操作链接文件
摘要:本文主要学习了在Linux系统中创建链接文件的命令。
ln命令
ln命令用于给文件创建链接,是Link的缩写。
基本语法
- 1 [root@localhost ~]# ln [选项] 源文件 目标文件
选项说明
- 1 -s:建立软链接文件。如果不加-s,则建立硬链接文件。如果源文件是在当前路径下,可以使用相对路径,否则如果不在当前路径下,则必须写成绝对路径。
- 2 -f:强制。如果目标文件已经存在,则删除目标文件后再建立链接文件。
使用举例
- 1 [root@localhost home]# ls
- 2 hello test
- 3 [root@localhost home]# ln hello hello-hard
- 4 [root@localhost home]# ls
- 5 hello hello-hard test
- 6 [root@localhost home]# ln test test-hard
- 7 ln: "test": 不允许将硬链接指向目录
- 8 [root@localhost home]# ln -s hello hello-soft
- 9 [root@localhost home]# ls
- 10 hello hello-hard hello-soft test
- 11 [root@localhost home]# ln -s test test-soft
- 12 [root@localhost home]# ls
- 13 hello hello-hard hello-soft test test-soft
- 14 [root@localhost home]#