0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Linux] ハードリンクとシンボリックリンク_コマンド_ln

Last updated at Posted at 2025-02-03

ハードリンクとシンボリックリンクの違い

項目 ハードリンク (Hard Link) シンボリックリンク (Symbolic Link)
指し示す対象 元のファイルのデータブロック 元のファイルのパス
リンクの独立性 オリジナルと同じファイル扱い(どちらも実体) リンクは別ファイルとして扱われる
元ファイル削除時の影響 元ファイルを削除してもデータは残る 元ファイルを削除するとリンクは無効(壊れる)
異なるファイルシステム間で作成可能か 不可(同じファイルシステム内のみ) 可能(異なるファイルシステムでもOK)
ディレクトリへの適用 通常不可(ln コマンドで作成不可) 可能
ファイルの inode 同じ inode を共有 異なる inode を持つ
作成方法 ln <元ファイル> <リンク名> ln -s <元ファイル> <リンク名>
ls コマンドでの表示 同じ inode 番号を持つ -> で元ファイルを指す

lnコマンド

ln
$ ln [オプション] リンク元(実体) リンクファイル
オプション 由来 説明
デフォルト ハードリンクの作成
-s symbolic link シンボリックリンクの作成

ハードリンクの例

sh
$ echo "Hello" > original.txt
$ ln original.txt hardlink.txt
$ ls -li
123456 -rw-r--r-- 2 user user 6 Feb 2 12:00 original.txt  
123456 -rw-r--r-- 2 user user 6 Feb 2 12:00 hardlink.txt  

シンボリックリンクの例

sh
$ ln -s original.txt symlink.txt
$ ls -li
123456 -rw-r--r-- 1 user user 6 Feb 2 12:00 original.txt  
654321 lrwxrwxrwx 1 user user 12 Feb 2 12:01 symlink.txt -> original.txt  

Ping-t

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?