Linux Soft and Hard links detailed

Source: Internet
Author: User
Tags parent directory

Soft links

Soft Link: Windows-like shortcut,-> text file, but contains the address of the real file
If the source file is deleted, the soft connection is also deleted
Soft links can be placed on any file system
The directory can create a soft connection--and a different file from the source file, because the soft connect directory can be anywhere

command: [[email protected] omc]# ln-s ftl/ftl.soft   (first parameter indicates source file, inittab.soft means shortcut) view: [[email protected] omc]# Readlink Ftl.soft  (The destination file cannot be pre-existing and requires the LN command to be created) to remove the soft connection:: [[email protected] omc]#  rm-f oldboy_soft_link
Hard Links

Hard Links: Hard links (inode-consistent) are identical to the actual file size and creation date (same inode number), similar to copy, synchronous update.

Through the Inode index link, the hard link multiple file names point to the same index, the equivalent of the file entry, hard link a file has multiple portals, equivalent to file backup

principle: through the command ls–i, found that the hard link file and the source file I node number is the same, and the kernel is based on the file's I node to identify the file, the two files of the I node is the same, all is considered a file, all simultaneously write and modify data.
Hard links cannot span file systems, that is, cannot span partitions, similar to the hard links in windows that do not place the C drive on the D drive.

Unlike copy: the copy is different from the creation date of the real file
Hard links belong to replication, source file deletion does not affect hard links
When all the hard links and source files are deleted, and then the new data is used to occupy this space, the disk is detected, and the deleted data is recycled
You can prevent files from being mistakenly deleted by setting hard links
Note that the catalog does not make hard links

Command: Ln/etc/inittab/test/inittab.hard view: ls-l/etc/inittab/test/inittab.hard View All Files Inode:find/-type F | Xargs Ls-lhi | More

File link

Summary of File Links:
-1.ln default without parameters to the case of creating a hard link,-s means creating a soft connection
0. A soft connection can be viewed through readlink to view its point
1. Delete Soft connection has no effect on original file and hard link file
2. Removing hard links has no effect on source files and soft connection files
3. Delete the original file, no impact on hard links, but will cause soft connection failure
4. Deleting source files and hard links will cause the whole file to be deleted (no background process calls)
5. The camera function of the hardware device is the principle of applying the hard link
6. Hard links and source files have the same inode, can be considered to be the same file or multiple portals of the same file
7. Delete hard links and source files at the same time, the entire file will be deleted
8. The soft connection and the source file have different inode because of the creation of 2 different files, equivalent to shortcuts, and the location of the source files pointing to
9. Soft connection is a new file, which records the path of the original file, the name of the soft connection must be created by LN, cannot exist beforehand

Directory Links

Summary of directory Links:
1. For a directory, you cannot create a hard link, you can create a soft connection
Default is 2 "
1. The created directory itself is a hard link.
2. The hidden directory under the new directory Ett. (dot) Another hard link to the new directory created, also counted as a link number
Therefore, the number of hard links is 2 "
Hard links cannot cross file systems (if the inode is different when 2 file systems are not allowed)
2. For a directory you can create a soft connection, because the soft connection can cross the system, equivalent to the directory shortcut, there is a new inode
3. Hard links to directories cannot span file systems (hard link principle)
4. There is a hard-link symbol below each directory. , and a hard link corresponding to the parent directory.
5. Create a subdirectory within the parent directory, and increase the number of links in the parent directory by 1 (one more). To point to the parent directory)
However, if you create a file, the number of links does not increase (there will be no in the file: To point to the upper directory)

Linux Soft and Hard links detailed

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.