A command ln under Linux
Role: Create a soft link or a hard link
Each file created under the Linux system will generate an index node abbreviation (inode) for this file, and each file contains user data and metadata (metadata)
The real content of the file is recorded in the user data.
The metadata records the attached properties of the file, such as file size, creation time, owner, etc., where the index node mentioned above is stored in the metadata. In Linux, the file name is not a unique identifier, index Onde is the only indicator, the system to find the file is also through Index node to find the content data block.
How to view the file's index node:
? /users/zhangzhi >ls -i31615656 androidstudioprojects 30836545 go 1152719 applications 49115578 images31827389 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.zip32072972 app 41999857 webwork 1009500 code 13208610 game configuration 22509232 Databak
The preceding number sequence we see is the 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 portals.
Instructions:
ln [option] Link_file source_file
(Link_file is the file to create the link file, Source_file is the newly created link file)
-F is created, it is deleted with the file name.
-I ask before deleting.
Example:
Ln-s myfile mylink Creating a soft link to a myfile file MyLink
ln myfile MyLink to establish myfile hard link MyLink
Soft links
Ln-s myfile MyLink
When a soft link is created, the user's data is stored in a pointer to the original file path, not a record of the file itself. But it has its own index node sequence.
So, the soft link is actually a new file, but this file is very special, because his user data is not in the file content, but a pointer to other files.
Soft links have the following features:
Multiple soft links have multiple different index node
Not only can you create a file, but you can also create a soft link to the directory
Soft links can cross file system
Deleting a soft link does not affect the original file, but the original file is deleted, and the soft link becomes a dead link.
Hard Links
ln myfile MyLink
After the hard link is created, the user data is stored in the file itself, and the other user data and metadata are the same as myfile, the only difference is the file name.
So a hard link is a file with multiple filenames, but multiple filenames point to the same index node
In this case, a hard link is the same file with multiple aliases.
Hard links have the following several special:
Originating from: Using ln to create soft link connections and hard links under Linux
They have the same index node
Have the same data record
You can only create a hard link on an already existing file
Remove any of the other hard links that are not affected.
You can only make hard links to files
- The difference between ssh-agent and SSH
- Env custom development, test, release environment variables
- Linux kernel Rename command bulk modify name
- Linux under wget command use Help
- Why Linux systems like to use ~ to represent the home directory
Use ln to create soft links and hard links under Linux