软链接&&硬链接

 

root@ubuntu:/home/shay/Documents/test# cat lnkt2
hello world
root@ubuntu:/home/shay/Documents/test# ls
lnkt2
root@ubuntu:/home/shay/Documents/test# ln lnkt2 lnkt1
root@ubuntu:/home/shay/Documents/test# mkdir testdir1
root@ubuntu:/home/shay/Documents/test# mv lnk2 ./testdir1/
mv: cannot stat 'lnk2': No such file or directory
root@ubuntu:/home/shay/Documents/test# mv lnkt2 ./testdir1/
root@ubuntu:/home/shay/Documents/test# ls
lnkt1  testdir1
root@ubuntu:/home/shay/Documents/test# tree .
.
├── lnkt1
└── testdir1
    └── lnkt2

1 directory, 2 files
root@ubuntu:/home/shay/Documents/test# ln testdir1 testdir2
ln: testdir1: hard link not allowed for directory
root@ubuntu:/home/shay/Documents/test# ln -s testdir1 testdir2
root@ubuntu:/home/shay/Documents/test# ls
lnkt1  testdir1  testdir2
root@ubuntu:/home/shay/Documents/test# cd testdir2
root@ubuntu:/home/shay/Documents/test/testdir2# ls
lnkt2
root@ubuntu:/home/shay/Documents/test/testdir2# cat lnkt2
hello world
root@ubuntu:/home/shay/Documents/test/testdir2# cd ..
root@ubuntu:/home/shay/Documents/test# rm -rf testdir1
root@ubuntu:/home/shay/Documents/test# ls
lnkt1  testdir2
root@ubuntu:/home/shay/Documents/test# ll
total 12
drwxr-xr-x  2 root root 4096 Jul  9 02:24 ./
drwxr-xr-x 15 shay shay 4096 Jul  9 02:12 ../
-rw-r--r--  1 root root   12 Jul  9 02:13 lnkt1
lrwxrwxrwx  1 root root    8 Jul  9 02:17 testdir2 -> testdir1

概念参考:

软链接和硬链接详解 | 《Linux就该这么学》

INODE定义以及metadata

What is an inode?

Linux® must allocate an index node (inode) for every file and directory in the filesystem. Inodes do not store actual data. Instead, they store the metadata where you can find the storage blocks of each file’s data.

Metadata in an inode

The following metadata exists in an inode:

  • File type
  • Permissions
  • Owner ID
  • Group ID
  • Size of file
  • Time last accessed
  • Time last modified
  • Soft/Hard Links
  • Access Control List (ACLs)

参考:

What are inodes in Linux? -

问题1:cp -l 和 ln有什么区别?

执行的结果是没有区别的,都是硬链接,区别在于cp -l可以附加递归。

参考:hard link - Is there a difference between hardlinking with cp -l or ln? - Unix & Linux Stack Exchange

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值