Linux ln command operation guide

  
                

ln is an important command in the Linux system. It can establish links for files and maintain the synchronization of linked files. The following small series will introduce you to how to use the ln command under Linux, and learn more through examples.

1. Use the ln command to create a symbolic link to the file.

The symbolic link under Linux is similar to the shortcut for Windows.

Using the ls command, you can see that the newly created symbolic link has a separate inode, that is, the symbolic link will occupy an inode, but the actual content still points to the

source file. Block area.

# touch /tmp/file

# ls -lhi /tmp/file

3441 -rw-r--r-- 1 root root 0 Jan 1 00: 09 /tmp/file

#

# ln -fs /tmp/file /tmp/symbolic_link

# ls -lhi /tmp/symbolic_link

3647 lrwxrwxrwx 1 root root 9 Jan 1 00:10 /tmp/symbolic_link -" /tmp/file

#

2. Deleting the symbolic link file actually deletes the inode instead of Will affect the block area pointed to by the source file;

And if the source file is deleted, then the symbolic link file is basically useless.

# echo “link test” 》 /tmp/file

# cat /tmp/file

link test

#

# rm /tmp/symbolic_link

# cat /tmp/file

link test

#

# ln -fs /tmp/file /tmp /symbolic_link

#

# rm /tmp/file

# cat /tmp/symbolic_link

cat: can‘t open ’/tmp/Symbolic_link‘: No such file or directory

#

# ls -lhi /tmp/symbolic_link

7357 lrwxrwxrwx 1 root root 9 Jan 1 00:22 /tmp/symbolic_link -> /tmp/file

#

3. Use the ln command to create a hard link.

As you can see, creating a hard link uses the same inode and copies a block of the source file.
Previous12Next Total 2 Pages

Copyright © Windows knowledge All Rights Reserved