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
概念参考:
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)
参考:
问题1:cp -l 和 ln有什么区别?
执行的结果是没有区别的,都是硬链接,区别在于cp -l可以附加递归。