1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UNIX(mac)のシンボリックリンクとlnコマンド

Last updated at Posted at 2020-08-20

UNIXのリンクとは

UNIXのリンクはファイルやディレクトリに別名をつけることができる仕組み。
つまりmacOSにおける「エイリアス(別名)」、Windowsでいう「ショートカット」はUNIXでは「リンク」と呼ぶ。

リンクは2種類

・ハードリンク
・シンボリックリンク(多くの場合はこっちを使う)

シンボリックリンクがよく使われる理由

・リンク先がわかりやすい
・ディレクトリへのリンクが作成できる
・異なるディスクボリュームへのリンクが作成できる

lnコマンドでシンボリックリンクを作成する

構文

ln [オプション] 元のファイルパス リンクのファイルパス
オプションに「-s」を指定することでシンボリックリンクを作成する。
(-sがない場合はハードリンクの作成になる。)

ファイルに対してシンボリックリンクを作成する例

ln -s first.txt second.txt
ln -s first.txt third
ファイルの順番はcpコマンドと同様「元」「作成先」の順。

ディレクトリに対してシンボリックリンクを作成する例

ln -s src/app01/db myDB

参考

これから学ぶmacOSターミナル

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?