Linux common commands - the link command

Links command: ln

ln -s [original document] [destination file] 
    command English original intent: link 
    Description: Create link files 
        option: -s to create a soft link

  Hard link feature:

  1 have the same memory block and the i-node block, it can be seen as a same file

  2. A node can be identified by the i

  3. can not cross partitions

  4. Can not use for directory

[the root @ localhost ~] # LS 
Anaconda-Binaries binaries.tar.gz the ks.cfg the ks.cfg Initial-Setup-test123 
[the root @ localhost ~] # LN /root/anaconda-ks.cfg /tmp/ana.hard 
[ root @ localhost ~] # ls -i /root/anaconda-ks.cfg /tmp/ana.hard - i nodes of the two documents are identical 
25165890 /root/anaconda-ks.cfg 25165890 /tmp/ana.hard

  Soft link feature:

  1. similar to Windows shortcuts

  2. soft link has its own i-node block and block, but pieces of data stored in only the file name and i-node number of the original document, and not the actual file data

  3. soft link permissions are 777, but the actual permissions need to look at the original file permissions

  4. modify any file, other changes are

  5. Delete the original file, soft links can not be used (original document must write the absolute path, otherwise the original and target files must be in the same directory)

[root@localhost ~]# ls
anaconda-ks.cfg  binaries  binaries.tar.gz  initial-setup-ks.cfg  test123  test3
[root@localhost ~]# ln -s /root/test3 /tmp/test3.soft
[root@localhost ~]# ln  /root/test3 /tmp/test3.hard
[root@localhost ~]# ll -i
总用量 20172
25165890 -rw-------.  2 root root      2165 5月  13 16:15 anaconda-ks.cfg
17070804 drwxr-xr-x. 14  501 games      175 6月  17 2017 binaries
25288936 -rw-r--r--.  1 root root  20647102 6月  22 2017 binaries.tar.gz
25165908 -rw-r--r--.  1 root root      2213 5月  13 16:17 initial-setup-ks.cfg
 8546987 drwxr-xr-x.  3 root root        19 6月  15 16:59 test123
25708548 -rw-r--r--.  2 root root         0 6月  16 11:15 test3
[root@localhost ~]# ll -i /tmp/
总用量 256
17070621 -rw-------. 1 root  root   2165 6月  15 16:22 ana
17071146 -rw-------. 1 root  root   2165 5月  13 16:15 anaconda-ks.cfg
25165890 -rw-------. 2 root  root   2165 5月  13 16:15 ana.hard
25521547 drwxr-xr-x. 3 root  root     19 6月  15 16:25 test1
 8388685 drwxr-xr-x. 3 root  root     19 6月  15 16:24 test3
25708548 -rw-r--r--. 2 root  root      0 6月  16 11:15 test3.hard
17071129 lrwxrwxrwx. 1 root  root     11 6月  16 11:16 test3.soft -> /root/test3
[root@localhost ~]# echo 111 >> /root/test3
[root@localhost ~]# cat /tmp/test3.soft 
111
[root@localhost ~]# cat /tmp/test3.hard 
111
[root@localhost ~]# echo 2222 >> /tmp/test3.soft 
[root@localhost ~]# cat /tmp/test3.hard 
111
2222
[root@localhost ~]# cat /root/test3 
111
2222
[root@localhost ~]# echo 3333 >> /tmp/test3.hard 
[root@localhost ~]# cat /root/test3
111
2222
3333
[root@localhost ~]# cat /tmp/test3.soft 
111
2222
3333
[root@localhost ~]# rm -rf /root/test3
[root@localhost ~]# cat /tmp/test3.hard 
111
2222
3333
[root @ localhost ~] # /tmp/test3.soft CAT 
CAT: /tmp/test3.soft: No such file or directory

  

Guess you like

Origin www.cnblogs.com/Simon212/p/11028347.html