Maison  >  Article  >  Opération et maintenance  >  Qu’est-ce qu’un lien logiciel Linux ?

Qu’est-ce qu’un lien logiciel Linux ?

青灯夜游
青灯夜游original
2022-06-17 16:14:448306parcourir

Sous Linux, un lien symbolique équivaut à un raccourci sous Windows, existant sous la forme d'un chemin ; le fichier est en fait un fichier texte qui contient les informations d'emplacement d'un autre fichier. La syntaxe de création d'un lien logiciel est "ln -s target source". Le paramètre "target" représente le fichier (dossier) cible, c'est-à-dire le fichier (dossier) vers lequel pointe, et le paramètre "source" représente le soft link. nom du lien du répertoire actuel, c'est-à-dire le fichier source (dossier).

Qu’est-ce qu’un lien logiciel Linux ?

L'environnement d'exploitation de ce tutoriel : système linux7.3, ordinateur Dell G3.

Les liens Linux sont divisés en deux types, l'un est appelé Hard Link et l'autre est appelé Symbolic Link, également connu sous le nom de Soft Link.

Connexion logicielle Linux

équivaut à un raccourci dans Windows Puisque le fichier créé par la connexion logicielle est un nouveau fichier indépendant, il occupera indoe et bloquera

C'est en fait un document spécial. Dans un lien symbolique, le fichier est en fait un fichier texte qui contient les informations d'emplacement d'un autre fichier.

  • Les liens logiciels existent sous forme de chemins. Semblables aux raccourcis du système d'exploitation Windows

  • Les liens logiciels peuvent traverser des systèmes de fichiers, les liens physiques ne le peuvent pas

  • Les liens logiciels peuvent créer un lien vers un nom de fichier inexistant

  • Les liens logiciels peuvent créer des liens vers des répertoires Lien

1. Syntaxe de création

ln -s source cibleln -s target source

解释下:

ln -s:表示创建一个软连接;

target:表示目标文件(夹)【即被指向的文件(夹)】

source:表示当前目录的软连接名。【源文件(夹)】

2 具体示例

  • step 1.创建测试文件及文件夹
[root@server6 ~]# mkdir test_chk
[root@server6 ~]# touch test_chk/test.txt 
[root@server6 ~]# echo "hello spark" > test_chk/test.txt 
[root@server6 ~]# cat test_chk/test.txt 
hello spark
[root@server6 ~]# ll
总用量 84
-rw-------.  1 root root  1257 6月  16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root  4096 11月  1 10:28 azkabanJob
-rw-r--r--.  1 root root 67322 11月  4 10:24 azkabanJob.zip
drwxr-xr-x.  4 root root    37 7月  13 11:01 hadoop_temp
-rw-r--r--.  1 root root    54 7月   4 14:11 HelloLinux.txt
drwxr-xr-x.  2 root root    22 11月  4 10:41 test_chk
-rw-r--r--.  1 root root    67 10月  8 15:52 zookeeper.out
[root@server6 ~]# ln -s test_chk/ test_chk_ln
[root@server6 ~]# ll
总用量 84
-rw-------.  1 root root  1257 6月  16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root  4096 11月  1 10:28 azkabanJob
-rw-r--r--.  1 root root 67322 11月  4 10:24 azkabanJob.zip
drwxr-xr-x.  4 root root    37 7月  13 11:01 hadoop_temp
-rw-r--r--.  1 root root    54 7月   4 14:11 HelloLinux.txt
drwxr-xr-x.  2 root root    22 11月  4 10:41 test_chk
lrwxrwxrwx.  1 root root     9 11月  4 10:42 test_chk_ln -> test_chk/
-rw-r--r--.  1 root root    67 10月  8 15:52 zookeeper.out
[root@server6 ~]# cd test_chk_ln/
[root@server6 test_chk_ln]# ll
总用量 4
-rw-r--r--. 1 root root 12 11月  4 10:41 test.txt
[root@server6 test_chk_ln]# cat test.txt 
hello spark
[root@server6 test_chk_ln]# ll
总用量 4
-rw-r--r--. 1 root root 12 11月  4 10:41 test.txt
[root@server6 test_chk_ln]# cat test.txt 
hello spark

注意

1、创建软连接时,不用创建文件夹。

2、命令示例解释

执行的命令是: ln -s /storage/lawson/scores scor

其含义就是:将scor指向 /storage/lawson/scores/目录下

Qu’est-ce qu’un lien logiciel Linux ?

这里是当前的scor 指向 /storage/lawson/scores 中。这里显示红色,是因为/storage/lawson/scores这个目录不存在,如果创建该目录,那就可以得到蓝色的显示了。

Qu’est-ce qu’un lien logiciel Linux ?
需要注意的是,当前所有目录下的文件都不能重名,因为我之前有一个文件夹是scores,所以这里就简单的命名成了scor

软连接的删除

rm -rf ./test_chk_ln/ 会删除文件夹下的所有内容,但是没有删除这个链接;
rm -rf ./test_chk_ln

Explication :
  • ln -s : signifie créer un lien symbolique
target : représente le fichier cible (dossier) [c'est-à-dire le fichier pointé (dossier)]

source : représente le nom du lien symbolique du répertoire actuel. [Fichier source (dossier)]
  • 2 Exemple spécifique

étape 1. Créer des fichiers et des dossiers de test

🎜
[root@server6 test_chk_ln]# cd ..
[root@server6 ~]# ll
总用量 84
-rw-------.  1 root root  1257 6月  16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root  4096 11月  1 10:28 azkabanJob
-rw-r--r--.  1 root root 67322 11月  4 10:24 azkabanJob.zip
drwxr-xr-x.  4 root root    37 7月  13 11:01 hadoop_temp
-rw-r--r--.  1 root root    54 7月   4 14:11 HelloLinux.txt
drwxr-xr-x.  2 root root    22 11月  4 10:41 test_chk
lrwxrwxrwx.  1 root root     9 11月  4 10:42 test_chk_ln -> test_chk/
-rw-r--r--.  1 root root    67 10月  8 15:52 zookeeper.out
[root@server6 ~]# rm -rf ./test_chk_ln/
[root@server6 ~]# ll
总用量 84
-rw-------.  1 root root  1257 6月  16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root  4096 11月  1 10:28 azkabanJob
-rw-r--r--.  1 root root 67322 11月  4 10:24 azkabanJob.zip
drwxr-xr-x.  4 root root    37 7月  13 11:01 hadoop_temp
-rw-r--r--.  1 root root    54 7月   4 14:11 HelloLinux.txt
drwxr-xr-x.  2 root root     6 11月  4 10:42 test_chk
lrwxrwxrwx.  1 root root     9 11月  4 10:42 test_chk_ln -> test_chk/
-rw-r--r--.  1 root root    67 10月  8 15:52 zookeeper.out
[root@server6 ~]# cd test_chk
[root@server6 test_chk]# ll
总用量 0
[root@server6 test_chk]# ll
总用量 0
[root@server6 ~]# rm -rf ./test_chk_ln
[root@server6 ~]# ll
总用量 84
-rw-------.  1 root root  1257 6月  16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root  4096 11月  1 10:28 azkabanJob
-rw-r--r--.  1 root root 67322 11月  4 10:24 azkabanJob.zip
drwxr-xr-x.  4 root root    37 7月  13 11:01 hadoop_temp
-rw-r--r--.  1 root root    54 7月   4 14:11 HelloLinux.txt
drwxr-xr-x.  2 root root    22 11月  4 10:44 test_chk
-rw-r--r--.  1 root root    67 10月  8 15:52 zookeeper.out
[root@server6 ~]# cd test_chk/
[root@server6 test_chk]# ll
总用量 4
-rw-r--r--. 1 root root 12 11月  4 10:44 test.txt
🎜🎜🎜Remarque🎜🎜🎜🎜1. un dossier. 🎜🎜2. Explication de l'exemple de commande🎜🎜La commande exécutée est : ln -s /storage/lawson/scores scor🎜🎜La signification est : pointez scor vers le répertoire /storage/lawson/scores/🎜 🎜Insérer la description de l'image ici🎜🎜Voici le point scor actuel vers /storage/lawson/scores. La couleur rouge est affichée ici car le répertoire /storage/lawson/scores n'existe pas. Si vous créez ce répertoire, vous pouvez obtenir un affichage bleu. 🎜🎜Insérer la description de l'image ici
Besoin de payer attention Le problème est que les fichiers de tous les répertoires actuels ne peuvent pas avoir le même nom, car j'avais auparavant un dossier scores, donc je l'ai simplement nommé scor. 🎜🎜🎜🎜Suppression des liens symboliques🎜🎜🎜🎜rm -rf ./test_chk_ln/ supprimera tout le contenu du dossier, mais pas le lien ;
rm - rf ./test_chk_ln supprime uniquement ce lien symbolique et ne supprime pas le contenu suivant. 🎜🎜🎜Démonstration d'erreur🎜🎜rrreee🎜Vous pouvez constater que le contenu du dossier a été supprimé. . . 🎜🎜🎜Supprimer correctement les connexions logicielles🎜🎜rrreee🎜Recommandations associées : "🎜Tutoriel vidéo Linux🎜"🎜

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn