Soft links and hard connections for Linux key concepts

Source: Internet
Author: User

Tags: soft link hard connection

when we log in to the Linux System, we use the ls–l command to list the files in the directory. Some of the file's display formats are as follows:

lrwxrwxrwx. 1 root root 7 Jul 09:18 RC -- RC.D/RC

This is what the ghost, first contact, there will be a very strange feeling, do not know why this file and other file display form is different. When we know something about the linux file type, it's easy to see that this kind of file is called a soft link file.

in the Linux In addition to the soft-link text as shown above, there is another link called a hard connection. Hard connect like a person has a name, no matter what name, people's various physiological data will not change. The same is true for hard joins, which change content as the content of the source file increases or decreases.

The difference between a soft link and a hard connection:

Hard Connect:

Creating a hard link adds additional record entries to reference the file

corresponds to a physical file on the same file system

Each file references the same inode

Increase number of links at creation time

When the Ask Price is deleted:

RM link for descending count of commands

file to exist, at least one link number

When the number of links is zero, the file is deleted

cannot span drives or partitions

Syntax:ln filename [linkname]

                 [[email  protected] test]# ll                 total 8                 drwxr-xr-x   2 root root 4096 Jul 31  17:56 .                 Dr-xr-x---.  27 root root 4096 jul 31 17:55                  [[email  protected] test]# touch hardlink.txt                 [[email protected] test]# ll                 total 8                 drwxr-xr-x   2 root root 4096 jul 31 17:56  .                 Dr-xr-x---.  27 root root 4096 jul 31 17:55                  -rw-r--r--    1 root root    0 jul 31 17:56 hardlink.txt                 [[email  protected] test]# ln hardlink.txt hardlink1.txt                  [[email protected] test]# echo   "AAAAAA"  > hardlink.txt                  [[email protected]  test]# cat hardlink.txt                  aaaaaa                 [[email protected] test]# cat hardlink1.txt                  aaaaaa                 [[email protected]  test]# rm hardlink                 rm: cannot remove  ' Hardlink ': no such file or  directory                [[ Email protected] test]# rm hardlink.txt                  rm: remove regular file  ' Hardlink.txt '? y                 [[email protected] test]#  cat hardlink1.txt                  aaaaaa                 [[email protected] test]#                 [[email protected] test]# mkdir hardlink                 [[email  protected] test]# ln hardlink hardlink2                 ln:  ' Hardlink ': hard link not allowed for directory                 [[email protected]  test]#

Soft Links:

a symbolic link points to another file

Ln–s The name of the link and the referenced file are displayed

The content of a symbolic link is the name of the file it references

The catalog can also be soft-linked

can span partitions

the path to another file, its size is the length of the path string to which it is pointing, no increase or decrease

The reference count for the inode of the target file ;

Syntax:ln-s filename [linkname]

                [[email  protected] test]# touch symbolic.txt                 [[email protected] test]# mkdir symbolic                 [[email  protected] test]# cp -r /tmp/* symbolic                 [[email protected] test]# ln -s  symbolic.txt symbolic1.txt                 [[email protected] test]# ln -s symbolic symbolic1                 [[email  Protected] test]# ls -l                total 4                 drwxr-xr-x 10  root root 4096 Jul 31 18:01 symbolic                 lrwxrwxrwx  1 root root     8 Jul 31 18:03 symbolic1 -> symbolic                 lrwxrwxrwx  1  Root root   12 jul 31 18:01 symbolic1.txt -> symbolic.txt                 -rw-r--r--   1 root root    0 Jul 31 18:00 symbolic.txt      &nbSp;          [[email protected] test]# rm  -f symbolic.txt                  [[email protected] test]# ls -l                 total 4                 drwxr-xr-x 10 root root 4096  Jul 31 18:01 symbolic                 lrwxrwxrwx  1 root root    8 jul  31 18:03 symbolic1 -> symbolic                 lrwxrwxrwx  1 root root    12 jul 31 18:01 symbolic1.txt -> symbolic.txt                 [[email protected] test]#

Summary: From the top you can see that the hard connection file has two restrictions: 1. do not allow the creation of hard connections to the directory;2. only allow links to be created between files in the same file system. Soft links do not have the above two restrictions, you can link to the directory, but also can be linked across the partition. Hard Connect source file Delete, link file can still be used, soft link source file is deleted, link file is invalid. The same point is that only the deletion of linked files does not affect the contents of the source file.

This article from the "11880696" blog, reproduced please contact the author!

Soft links and hard connections for Linux key concepts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: