ln :创建链接文件

  • Post author:
  • Post category:其他



ln :创建链接文件


链接文件:


• 硬链接

:指通过索引节点号来进行链接。硬链接文件和源文件是一个inode节点号,具有相同的性质,源文件被删除,硬链接 文件还能继续访问文件内容,故可以通过创建硬链接来防止重要文件被误删。


• 软连接

(符号链接):类似于windows的快捷方式,是一个特殊的文件,inode 号和源文件不同,软链接文件存放的是源文件的路径名。若源文件被删除,软链接文件无法访问文件内容。

用法:
	ln [选项]... 目标 
	选项:
			-s :创建符号链接文件
			-f  :强行删除任何已存在的目标文件
[root@host test]# touch file
[root@host test]# stat file
  文件:"file"
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:13133132    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2020-05-08 19:09:46.593513744 +0800
最近更改:2020-05-08 19:09:46.593513744 +0800
最近改动:2020-05-08 19:09:46.593513744 +0800
创建时间:-


• ln :创建硬链接文件

[root@host test]# stat file_hard.link
  文件:"file_hard.link"
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:13133132    硬链接:2
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2020-05-08 19:09:46.593513744 +0800
最近更改:2020-05-08 19:09:46.593513744 +0800
最近改动:2020-05-08 19:11:34.007517022 +0800
创建时间:-
[root@host test]# cat file
[root@host test]# cat file_hard.link
[root@host test]# echo "hello world" > file
[root@host test]# cat file_hard.link
hello world
[root@host test]# rm -f file
[root@host test]# cat file_hard.link
hello world


• ln -s:创建软链接文件

[root@host test]# touch file
[root@host test]# ln -s file file.link
[root@host test]# stat file
  文件:"file"
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:13133132    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2020-05-08 19:13:49.150521147 +0800
最近更改:2020-05-08 19:13:49.150521147 +0800
最近改动:2020-05-08 19:13:49.150521147 +0800
创建时间:-
[root@host test]# stat file.link
  文件:"file.link" -> "file"
  大小:4               块:0          IO 块:4096   符号链接
设备:fd00h/64768d      Inode:13133151    硬链接:1
权限:(0777/lrwxrwxrwx)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2020-05-08 19:14:38.639522657 +0800
最近更改:2020-05-08 19:14:24.411522223 +0800
最近改动:2020-05-08 19:14:24.411522223 +0800
创建时间:-
[root@host test]# echo "hello world" > file
[root@host test]# cat file
hello world
[root@host test]# cat file.link
hello world
[root@host test]# rm -f file
[root@host test]# cat file.link
cat: file.link: 没有那个文件或目录
[root@host test]# ls
file.link

——————————————————————————————————-

返回目录



版权声明:本文为weixin_46470342原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。