Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ln command to create soft link and hard link in Linux system

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to use ln command to create soft link and hard link in Linux system, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Every time a file is created in the Linux system, the system generates an index node abbreviation (inode) for the file, and each file contains user data (user data) and metadata (metadata).

The true contents of the file are recorded in the user data.

The metadata records the additional attributes of the file, such as file size, creation time, owner, etc., in which the index node mentioned above is stored in the metadata. In linux, the file name is not the only identification of the file, but the index onde is the only mark, and the system searches the file through index node to find the content data block.

How to view the index node of a file:

The code is as follows:

/ Users/zhangzhi > ls-I

31615656 AndroidStudioProjects 30836545 go

1152719 Applications 49115578 images

31827389 CNode 13208576 ktsgs.zip

595399 Desktop 44722768 pandoc_demo

595275 Documents 49218456 pgadmin.log

595277 Downloads 15078624 pomelo

7094352 LevelTest 1009499 project

7098493 LevelTest.zip 1011801 qdb

595388 Library 5901898 qdb.zip

595439 Movies 23150187 test

595441 Music 1010768 tmp

595443 Pictures 17956310 trunk

595445 Public 17970255 trunk.zip

32072972 app 41999857 webwork

1009500 code 13208610 Game configuration

22509232 databak

The previous sequence of numbers we see is index node.

How to understand it, you can imagine it as a shortcut key in the windows operating system. Access to the same file provides multiple entries.

Directive:

The code is as follows:

Ln [option] link_file source_file

(link_file is the file to be linked, and source_file is the newly created linked file)

-f delete the same file name when it is created.

-I ask before deletion.

Example:

The code is as follows:

Ln-s myfile mylink

Establish a soft link mylink for myfile files

The code is as follows:

Ln myfile mylink

Establish a hard-link mylink for myfile

Soft link

Ln-s myfile mylink

After the soft link is created, what is stored in the user data is not the record of the file itself, but a pointer to the original file path. But it has its own index node sequence.

So, the soft link is actually a new file, but this file is special because its user data does not contain the contents of the file, but a pointer to other files.

Soft links have the following characteristics:

1. Multiple soft links have multiple different index node

two。 You can create not only files, but also directories.

3. Soft links can cross file systems

4. Deleting the soft link does not affect the original file, but when the original file is deleted, the soft link becomes a dead link.

Hard link

Ln myfile mylink

After the hard link is created, the records of the file itself are stored in the user data, and the other user data and metadata are the same as myfile, except for the file name.

So a hard link means that the same file has multiple file names, but multiple file names all point to the same index node.

In this way, a hard link is the same file with multiple aliases.

Hard links have the following special features:

1. They have the same index node.

two。 Have the same data record

3. Hard links can only be created on existing files

4. Delete any one of them and the other hard links will not be affected.

5. You can only make hard links to files.

This is the answer to the question about how to use the ln command to create soft links and hard links in the Linux system. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report