current position:Home>Soft connection, hard connection, Linux easy to mix words

Soft connection, hard connection, Linux easy to mix words

2022-01-26 23:29:44 Websoft9

This is my participation 8 The fourth of the yuegengwen challenge 5 God , Check out the activity details :8 Yuegengwen challenge

In the process of our study and practice , We often encounter two relative words :Linux Soft connection in 、 Hard to connect . These two words are easily confused 、 It's hard to distinguish , It will bring some problems in our use . today , Xiao Jiu will take you to sort out these two words ~

Soft connection

A soft connection is a file that points to another file , similar Windows Shortcut file in .

Soft connection query method

How can I know which files are soft link files ?

Let's get in first etc Catalog , Then list the files ( With re Keywords are screened as results )

[email protected]:/etc# ls -l | grep re
-rw-r--r-- 1 root root     367 Jan 27  2016 bindresvport.blacklist
drwxr-xr-x 2 root root    4096 Apr  9 06:04 firefox
lrwxrwxrwx 1 root root      33 Dec 25 16:13 localtime -> /usr/share/zoneinfo/Asia/Shanghai
-rw-r--r-- 1 root root     105 Jan 30 20:28 lsb-release
lrwxrwxrwx 1 root root      21 Jan 30 20:28 os-release -> ../usr/lib/os-release
drwxr-xr-x 4 root root    4096 Dec 25 16:13 resolvconf
lrwxrwxrwx 1 root root      29 Dec 25 16:13 resolv.conf -> ../run/resolvconf/resolv.conf
-rw-r--r-- 1 root root    3663 Jun  9  2015 screenrc
-rw-r--r-- 1 root root    4141 Jan 25  2018 securetty
-rw-r--r-- 1 root root    1656 Jul 25  2019 tmpreaper.conf

[email protected]:/etc# ls -l | grep ^l
lrwxrwxrwx 1 root root      33 Dec 25 16:13 localtime -> /usr/share/zoneinfo/Asia/Shanghai
lrwxrwxrwx 1 root root      19 Dec 26 00:11 mtab -> ../proc/self/mounts
lrwxrwxrwx 1 root root      21 Jan 30 20:28 os-release -> ../usr/lib/os-release
lrwxrwxrwx 1 root root      29 Dec 25 16:13 resolv.conf -> ../run/resolvconf/resolv.conf
lrwxrwxrwx 1 root root      23 Dec 25 16:08 vtrgb -> /etc/alternatives/vtrgb
 Copy code 

In the example above , We're running ls -l command , Shows several different types of files :

  • lrwxrwxrwx: This kind of l The beginning is the soft connection file
  • drwxr-xr-x: This kind of d The beginning is the directory
  • -rw-r--r--: This kind of - The beginning is the file

How to create soft connection

After knowing what soft connection is , We can do the soft connection by ourselves :

cd /root
ln -s /usr/share/zoneinfo/Asia/Shanghai2 mysoftlink
file mysoftlink
 Copy code 

Delete method of soft connection

rm -rf mysoftlink
 Copy code 

Be careful :

  1. The name of the connected file ( route ) Absolute path is recommended
  2. Wrong soft connection ( Also known as disconnection ) Use ls -l It's shown in red when you are
  3. Soft link is a file , There are data blocks in the hard disk
  4. The path information is stored in the database of soft connection file , Not real data
  5. Soft connections can be multi-level nested , for example :B Connect A,C Connect B,D Connect C

Hard to connect

Hard connection is relative to soft connection , It will be a little difficult to understand . Hard connection is to map different file names to the same storage block node .

for example : There is a data block in the server hard disk, which is a small video , The file name of this small video is :/data/mymedia.mp4.

Create a hard connection , Just use ln Command is enough

cd /data
ln /data/mymedia.mp4  mymedia2.mp4
 Copy code 

matters needing attention :

  1. The name of the connected file ( route ) Absolute path is recommended
  2. If a file adds a corresponding hard connection , Then the data will not be deleted when deleting the file
  3. Hard wired files store real block locations
  4. Only hard connections can be made to files , Instead of establishing a hard connection to a directory

Hard link and the same website in domain name management , use A The two domain names in the record configuration are of the same principle . Soft connection and domain name management cname Analysis is a similar principle .

This paper is written by Websoft9 Original release , Reprint please indicate the source .

copyright notice
author[Websoft9],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262329418740.html

Random recommended