Linux Basic Series (iv) Linux system soft link hard link knowledge

Source: Internet
Author: User

Soft Links

Soft Links (Soft Link) also known as symbolic links (Symboliclink) . Soft-link files in Linux are similar to shortcut keys in Windows systems. the soft link file in Linux is actually a special file , the file type is l. The actual line of the soft link file can be understood as a text file containing a soft link pointing to another source file's location information content , so by accessing this "shortcut" You can quickly navigate to the source file entity that the soft link points to.

File Soft Links

ln-s source file target file

Creating a soft Link:

Execute the command "ln-s source file link file"to complete the creation of the soft link.

myth: Creating a soft link source file is necessary , and the soft link file to be created cannot exist , and is created with the ln command.

Directory Soft Links

ln-s source file target file

a lot of soft links in the directory hard links are hardly used

Soft Link Knowledge summary

1) Soft links similar to Windows Shortcuts ( You can view them by Readlink)

2) Soft links like a text file that contains the path of the source file , pointing to the source file entity.

3) Delete the source file , the soft link file still exists , but cannot access the content of the source file path pointed to.

4) When the failure is usually a white-light red background flashing hint.

5) Execute the command "ln-s source file Soft link file " to complete the creation of a soft link (the target cannot exist )

6) Soft links and source files are different types of file inode numbers are also not the same.

7) Deleting a soft link file is available with the RM command.

Hard Links

a hard link is defined by an index node (Inode) to make the link. in the Linux (EXT2,EXT3,EXT4) file system , files that remain in the disk partition, regardless of type, assign a number to it , which is called the index node number Inode) referred to as the Inode, which is the number of the file in the system.

in the In a Linux file system , it is normal and permissible for multiple filenames to point to the same index node (Inode) . Files in this case are called hard links. Tip: A hard-link file is the equivalent of another entry in a file . One of the functions of a hard connection is to allow a file to have multiple valid path ports ( multiple portals ) so that users can establish hard links to important files to prevent "accidental deletion" of source data ( many hardware storage , the snapshot function in the store is to apply this principle and add a snapshot to a hard link . Why does a file create a hard link that prevents the data from being mistakenly deleted?

because the file system(ext2)the principle is,as long as the file's index node(Inodeindex)there is more than one hard link. Delete Only one of the hard links(that simply removes the link to the file that points to)does not affect the index node itself and other links(that is, the data file entity is not deleted),only when the last link to a file is deleted,A link to the deleted file's data block and directory will be released .,The space is occupied and overwritten by new data. At this,the data will no longer be recovered. Which means, in Linux system , Delete a static file ( No process call ) ( Directory is also a file ) the condition is that all hard-linked files associated with it are deleted.

Hard link schematic diagram:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/71/57/wKioL1XMGPeAI-4EAADUYFIwDwY282.jpg "title=" 3.png " alt= "Wkiol1xmgpeai-4eaaduyfiwdwy282.jpg" width= "650"/>

File Hard Links

LN source File Hard Link File

Catalog Hard Links

Directories do not allow hard links

Ls-a Show hidden files

to . the file at the beginning represents the hidden file

.. on behalf of the parent directory ( because they have the same inode)

Hard Link Knowledge summary
  • Multiple files that have the same inode number are mutually hard-linked files.

  • Deleting a hard link or deleting one of the source files , the file entity is not deleted.

  • The file entity is deleted only if the source file and all the corresponding hard-linked files are deleted .

  • when all the hard-link files and the source files are deleted , and then the new data will occupy the space of the file , or the disk fsck check , the deleted data will be collected by the system.

  • a hard-link file is another entrance to the file. ( equivalent to the front door of the supermarket , the back door ) .

  • You can prevent critical files from being mistakenly deleted by setting hard-link files to files .

  • You can create a hard link by executing the command "ln source file hard link file" .

  • hard-link files can be deleted with the RM command.

  • for static files ( no process is calling the file ) , when the corresponding number of hard links is 0 (i_link) The file is deleted. i_link View Method ( third column of the ls-l result )

Enterprise Production Soft link function

1, compile the software when the version number (/application/apache2.24) Access when you want to remove the version number (/application/apache), you can set the soft link to the compiled path. All Programs access the soft link file (/application/apache), and when the software is upgraded to a higher version , simply remove the link file to rebuild the soft link to the high version path (/application/ Apache

2, when the Enterprise Code is published (PHP program ), you need to upload all the code to a new temporary directory or new site directory. You can either use mv at the time of publishing or re-link to this new temporary directory or to a new site.

3, inconvenient directory mobile , using ln-s

link file enterprise face question

Describe the differences between soft links and hard links under Linux

1) By default without parameters , the ln command creates a hard link , and the ln command with the-s parameter creates a soft link.

2) The hard link file is the same as the Inode node number of the source file , and the Inode node number of the soft link file is different from the source file.

3) The ln command cannot create a hard link to a directory , but it can create soft links that are often used for soft links to directories.

4) Delete the soft link file , the source files and hard-linked files have no effect ;

5) Delete the hard-link files of the files , the source files and linked files have no effect ;

6) Delete the source file of the linked file , no impact on the hard link , will cause its soft link failure ( red white blinking )

7) Delete the source file and its hard link file , the whole file will be deleted.

8) The snapshot function in many hardware devices is similar to the principle of hard link.

9) Soft links can cross file system , hard links can not cross file system.

Enterprise interview answer to win the idea:

1) Introduction to soft and hard links.

2) the difference between soft and hard links for files.

3) The difference between the soft and hard links for the directory.


This article from "Flat Light is True" blog, reproduced please contact the author!

Linux Basic Series (iv) Linux system soft link hard link knowledge

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.