最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

在Linux系統(tǒng)上創(chuàng)建軟連接和硬連接的方法

 更新時(shí)間:2024年08月23日 09:12:33   作者:一口Linux  
這篇文章主要介紹了在Linux系統(tǒng)上創(chuàng)建軟連接和硬連接的方法,通過執(zhí)行 man ln 命令,可以看到這是在文件之間建立鏈接,而沒有提及是軟鏈接或硬鏈接,文中通過代碼和圖文介紹的非常詳細(xì),需要的朋友可以參考下

在本指南中,我將介紹什么是鏈接以及如何更好地使用它們以及所需的概念。

通過執(zhí)行 man ln 命令,可以看到這是在文件之間建立鏈接,而沒有提及是軟鏈接或硬鏈接。

shashi@linuxtechi ~}$ man ln

類似地,命令 man link 描述為調(diào)用鏈接功能創(chuàng)建文件。

Soft Link

軟鏈接顧名思義就是創(chuàng)建到新文件的新鏈接。在這種情況下,新文件的節(jié)點(diǎn)號將指向舊文件。

Hard Link

在這種情況下,舊文件和新文件都將指向相同的索引節(jié)點(diǎn)號。

Symbolic Link

在某些 Unix/Linux 系統(tǒng)中,符號和軟鏈接都被視為相同的。但是實(shí)際的差異是,新的文件和舊文件將指向一個新的 Inode 號碼,這將完全取決于實(shí)施。

注意: 在許多情況下,符號和軟鏈接術(shù)語可以互換使用,但是人們必須知道什么時(shí)候用什么。

Creating Hard Link

(1) man ln 命令輸出如下

shashi@linuxtechi ~}$ man ln
ln  - make links between files

(2) ln 命令無參數(shù),輸出如下

shashi@linuxtechi ~}$ln
ln: missing file operand
Try 'ln --help' for more information.

(3) 在兩個文件之間創(chuàng)建硬鏈接,首先檢查文件是否存在,否則將創(chuàng)建文件,然后鏈接它們。

shashi@linuxtechi ~}$ ls -la
total 24
drwx------  4 root root 4096 Feb  6 15:23 .
drwxr-xr-x 23 root root 4096 Jan 25 16:39 ..
-rw-r--r--  1 root root 3122 Jan 25 16:41 .bashrc
drwx------  2 root root 4096 Feb  6 15:23 .cache
-rw-r--r--  1 root root    0 Jan 25 16:41 .hushlogin
-rw-r--r--  1 root root  148 Aug 17  2015 .profile
drwxr-xr-x  2 root root 4096 Jan 25 16:41 .ssh

(4) 使用 touch 命令創(chuàng)建文件

shashi@linuxtechi ~}$ touch 123.txt
shashi@linuxtechi ~}$ ls -l
total 0
-rw-r--r-- 1 root root 0 Feb  6 15:51 123.txt

(5) 使用 cat 命令將內(nèi)容輸入到文件中,然后按 ctrl+c 保存并退出。

shashi@linuxtechi ~}$ cat > 123.txt
Welcome to this World!
^C

(6) 創(chuàng)建 123.txt 和 321.txt 文件之間的硬鏈接

shashi@linuxtechi ~}$ ln 123.txt 321.txt
shashi@linuxtechi ~}$ ls -l
total 8
-rw-r--r-- 2 root root 23 Feb  6 15:52 123.txt
-rw-r--r-- 2 root root 23 Feb  6 15:52 321.txt

(7) 檢查文件的索引節(jié)點(diǎn)號

shashi@linuxtechi ~}$ ls -li
total 8
794583 -rw-r--r-- 2 root root 23 Feb  6 15:52 123.txt
794583 -rw-r--r-- 2 root root 23 Feb  6 15:52 321.txt
$ cat 321.txt
Welcome to this World!

(8) 再創(chuàng)建一個名為 456.txt 的文件,并使用 ln 命令將其鏈接到 321.txt

shashi@linuxtechi ~}$  ls -li
total 12
794583 -rw-r--r-- 3 root root 23 Feb  6 15:52 123.txt
794583 -rw-r--r-- 3 root root 23 Feb  6 15:52 321.txt
794583 -rw-r--r-- 3 root root 23 Feb  6 15:52 456.txt
$ cat 456.txt
Welcome to this World!
shashi@linuxtechi ~}$   ls -l
total 12
-rw-r--r-- 3 root root 23 Feb  6 15:52 123.txt
-rw-r--r-- 3 root root 23 Feb  6 15:52 321.txt
-rw-r--r-- 3 root root 23 Feb  6 15:52 456.txt

(9) 當(dāng)源文件或這些文件中的任何一個被刪除時(shí),它不會影響其他文件。

shashi@linuxtechi ~}$ rm 123.txt
shashi@linuxtechi ~}$ ls -l
total 8
-rw-r--r-- 2 root root 23 Feb  6 15:52 321.txt
-rw-r--r-- 2 root root 23 Feb  6 15:52 456.txt
shashi@linuxtechi ~}$ ls -li
total 8
794583 -rw-r--r-- 2 root root 23 Feb  6 15:52 321.txt
794583 -rw-r--r-- 2 root root 23 Feb  6 15:52 456.txt
shashi@linuxtechi ~}$ cat 456.txt
Welcome to this World!

(10) 不允許跨目錄創(chuàng)建硬鏈接。

shashi@linuxtechi ~}$ls -l
total 8
-rw-r--r-- 2 root root 23 Feb  6 15:52 321.txt
-rw-r--r-- 2 root root 23 Feb  6 15:52 456.txt
shashi@linuxtechi ~}$ mkdir abc
shashi@linuxtechi ~}$ ln abc def
ln: abc: hard link not allowed for directory

(11) 對一個文件內(nèi)容的任何更改都將影響并相應(yīng)地更改其他文件的內(nèi)容。

shashi@linuxtechi ~}$ vi 321.txt
Welcome to this World!
You are welcomed to this new world
:wq
shashi@linuxtechi ~}$ ls -l
total 12
-rw-r--r-- 2 root root   59 Feb  6 16:24 321.txt
-rw-r--r-- 2 root root   59 Feb  6 16:24 456.txt
drwxr-xr-x 2 root root 4096 Feb  6 16:18 abc
shashi@linuxtechi ~}$ cat 456.txt
Welcome to this World!
You are welcomed to this new world

Creating Soft Link:

(1) 使用 touch 命令創(chuàng)建文件 src.txt,使用 cat 命令輸入內(nèi)容,然后按 ctrl+c 保存并退出。

shashi@linuxtechi ~}$ touch src.txt
shashi@linuxtechi ~}$ cat > src.txt
Hello World
^C
shashi@linuxtechi ~}$ ls -l
total 4
-rw-r--r-- 1 root root 12 Feb  6 16:32 src.txt

(2) 將目標(biāo)文件創(chuàng)建為 dst.txt,并使用 ln -s 命令創(chuàng)建符號鏈接 (也稱為軟鏈接)。查看 dst.txt 文件的內(nèi)容,可以看到與 src.txt 相同的內(nèi)容。

shashi@linuxtechi ~}$ ln -s src.txt dst.txt
shashi@linuxtechi ~}$  ls -l
total 4
lrwxrwxrwx 1 root root  7 Feb  6 16:33 dst.txt -> src.txt
-rw-r--r-- 1 root root 12 Feb  6 16:32 src.txt
shashi@linuxtechi ~}$  cat dst.txt
Hello World

(3) 在符號鏈接的情況下,源文件和目標(biāo)文件的 inode 號不同。在權(quán)限中出現(xiàn)字母 l,表明這些是鏈接。dst.txt ->src.txt 將是現(xiàn)在建立的新鏈接。

shashi@linuxtechi ~}$  ls -li
total 4
794584 lrwxrwxrwx 1 root root  7 Feb  6 16:33 dst.txt -> src.txt
794583 -rw-r--r-- 1 root root 12 Feb  6 16:32 src.txt

(4) 允許對目錄進(jìn)行符號創(chuàng)建

shashi@linuxtechi ~}$ mkdir abc
shashi@linuxtechi ~}$ ln -s abc def
$ ls -l
total 8
drwxr-xr-x 2 root root 4096 Feb  6 16:34 abc
lrwxrwxrwx 1 root root    3 Feb  6 16:34 def -> abc
lrwxrwxrwx 1 root root    7 Feb  6 16:33 dst.txt -> src.txt
-rw-r--r-- 1 root root   12 Feb  6 16:32 src.txt

(5) 源和目標(biāo)的 Inode 編號不同

shashi@linuxtechi ~}$  ls -li
total 8
794585 drwxr-xr-x 2 root root 4096 Feb  6 16:34 abc
794586 lrwxrwxrwx 1 root root    3 Feb  6 16:34 def -> abc
794584 lrwxrwxrwx 1 root root    7 Feb  6 16:33 dst.txt -> src.txt
794583 -rw-r--r-- 1 root root   12 Feb  6 16:32 src.txt

(6) 如前所述,可以為目錄創(chuàng)建符號鏈接。一旦創(chuàng)建了這些帶有符號鏈接的目錄,就可以在這些目錄中創(chuàng)建文件。當(dāng)在源目錄中創(chuàng)建文件時(shí),同樣的情況也會反映在目標(biāo)目錄中。

shashi@linuxtechi ~}$ $ cd abc
shashi@linuxtechi ~}$  touch 123.txt
shashi@linuxtechi ~}$  vi 123.txt
Hello
:wq!
shashi@linuxtechi ~}$  touch 456.txt
shashi@linuxtechi ~}$  cd ..
shashi@linuxtechi ~}$  ls -l
total 8
drwxr-xr-x 2 root root 4096 Feb  6 16:36 abc
lrwxrwxrwx 1 root root    3 Feb  6 16:34 def -> abc
lrwxrwxrwx 1 root root    7 Feb  6 16:33 dst.txt -> src.txt
-rw-r--r-- 1 root root   12 Feb  6 16:32 src.txt
shashi@linuxtechi ~}$ cd def
shashi@linuxtechi ~}$ ls -l
total 4
-rw-r--r-- 1 root root 6 Feb  6 16:37 123.txt
-rw-r--r-- 1 root root 0 Feb  6 16:36 456.txt
shashi@linuxtechi ~}$ cat 123.txt
Hello

Removing Soft Link / Symbolic Links

使用 rm 和 unlink 命令刪除軟鏈接或符號鏈接

# rm <soft-link-filename>
# unlink <soft-link-filename>

刪除軟鏈接目錄

# rm <soft-link-directory>
# unlink <soft-link-directory>

以上就是在Linux系統(tǒng)上創(chuàng)建軟連接和硬連接的方法的詳細(xì)內(nèi)容,更多關(guān)于Linux創(chuàng)建軟連接和硬連接的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Centos系統(tǒng)服務(wù)器查看端口是否開放的方法

    Centos系統(tǒng)服務(wù)器查看端口是否開放的方法

    本文介紹了在Centos系統(tǒng)服務(wù)器上如何查看端口是否開放的方法,通過telnet命令可以輕松實(shí)現(xiàn)。這對于服務(wù)器管理員來說非常重要,可以幫助他們及時(shí)發(fā)現(xiàn)端口問題并進(jìn)行修復(fù)。
    2023-03-03
  • 詳解Linux添加/刪除用戶和用戶組

    詳解Linux添加/刪除用戶和用戶組

    本文總結(jié)了Linux添加或者刪除用戶和用戶組時(shí)常用的一些命令和參數(shù)。具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2016-10-10
  • 詳解CentOS7下安裝Mysql和配置mysql

    詳解CentOS7下安裝Mysql和配置mysql

    本篇文章主要介紹了詳解CentOS7下安裝Mysql和配置mysql,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2016-12-12
  • centos7安裝mysql并jdbc測試實(shí)例詳解

    centos7安裝mysql并jdbc測試實(shí)例詳解

    這篇文章主要介紹了centos7安裝mysql并jdbc測試實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • 如何關(guān)閉http Methods中的Trace 提高安全意識

    如何關(guān)閉http Methods中的Trace 提高安全意識

    在配置文件http.conf 添加 TraceEnable off 即可關(guān)閉
    2013-02-02
  • 詳解CentOS的SVN服務(wù)器搭建與自動部署全過程

    詳解CentOS的SVN服務(wù)器搭建與自動部署全過程

    最近因?yàn)楣ぷ餍枰?,花了一個晚上時(shí)間折騰svn,網(wǎng)上的教程太亂太雜,還有很多是錯誤的,終于搞定了,所以想著把過程記錄下來。這篇文章主要介紹了CentOS的SVN服務(wù)器搭建與自動部署全過程,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-02-02
  • linux服務(wù)器查看進(jìn)程、線程數(shù)量方式

    linux服務(wù)器查看進(jìn)程、線程數(shù)量方式

    Linux服務(wù)器可通過ps、top查看進(jìn)程數(shù),ulimit調(diào)整最大進(jìn)程限制,dmidecode獲取CPU型號及物理核心/線程數(shù),當(dāng)前進(jìn)程數(shù)用ps -e | wc -l,服務(wù)進(jìn)程數(shù)用grep過濾,示例顯示1個CPU、6核心、12線程
    2025-07-07
  • Ubuntu?Server?22.04.5?入門篇:詳盡安裝部署指南

    Ubuntu?Server?22.04.5?入門篇:詳盡安裝部署指南

    這篇文章主要介紹了Ubuntu?Server?22.04.5?入門篇:詳盡安裝部署指南,需要的朋友可以參考下
    2025-03-03
  • 詳解在Linux下9個有用的touch命令示例

    詳解在Linux下9個有用的touch命令示例

    本篇文章主要介紹了詳解在Linux下9個有用的touch命令示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • Linux后臺運(yùn)行Java應(yīng)用的兩種方式詳解

    Linux后臺運(yùn)行Java應(yīng)用的兩種方式詳解

    在現(xiàn)代軟件開發(fā)和運(yùn)維實(shí)踐中,將 Java 應(yīng)用部署到 Linux 服務(wù)器并使其穩(wěn)定、可靠地在后臺運(yùn)行是每個開發(fā)者和系統(tǒng)管理員必須掌握的核心技能,本文將深入探討兩種主流的 Linux 后臺運(yùn)行 Java 應(yīng)用的方式,需要的朋友可以參考下
    2026-03-03

最新評論

柏乡县| 曲阜市| 香格里拉县| 抚松县| 大丰市| 西青区| 永寿县| 涟源市| 宿州市| 左权县| 东方市| 道真| 汉源县| 长泰县| 吉木乃县| 巴青县| 察哈| 磴口县| 九龙坡区| 特克斯县| 辽源市| 襄樊市| 潮州市| 尼玛县| 云梦县| 临澧县| 滨州市| 海林市| 城步| 静海县| 阿克| 九龙城区| 西和县| 奉节县| 建湖县| 永城市| 星子县| 札达县| 新津县| 南宁市| 赫章县|