LoginSignup
0
1

More than 1 year has passed since last update.

シンボリックリンクの作成/削除

Posted at

シンボリックリンクとは

ファイルを別のファイル名でリンク(参照)させるもの。
シンボリックリンクを削除してもリンク先のファイルは削除されない。
(ファイルだけでなく、ディレクトリも可能)

シンボリックリンクの作成コマンド

ln -s <リンク先> <シンボリックリンク名>

リンク先は、シンボリックリンクの場所からの相対パス、または絶対パス。
<シンボリックリンク名>は省略可(省略した場合、リンク先のファイル名(ディレクトリ名)と同じ名前のシンボリックリンクが作成される)

シンボリックリンクを作成

my_linksディレクトリの中にhello.txtへのシンボリックリンクを作成する。

《作成前の状態》

directory
├── my_links
│   └── // ここにシンボリックリンクを作成
├── target
│   └── hello.txt

シンボリックリンクを作成

$ cd my_links // 分かりやすいので移動
$ ln -s ../target/hello.txt link.txt // 作成コマンド

《作成後》

directory
├── my_links
│   └── link.txt -> ../target/hello.txt // できた!
├── target
│   └── hello.txt

シンボリックリンクの削除

$ cd my_links
$ unlink link.txt // 削除コマンド

《削除後》

directory
├── my_links
│  
├── target
│   └── hello.txt

参考

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