29
21

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 5 years have passed since last update.

ln コマンドでディレクトリを上書きする

Posted at

ln -sf と上書きのオプションをつけていても対象がディレクトリだった場合上書きされない場合があります。

CentOS6.4, ln (GNU coreutils) 8.4 #上書きされない
Ubuntu12.04, ln (GNU coreutils) 8.13 #上書きされない
Fedora 18, ln 8.17 #上書きされる
Arch Linux, ln 8.21 #上書きされない

な感じです。 ln コマンドがそんなにバージョンアップしてた事自体に驚きが隠せないのですが、どのバージョンでも可能な対策があります。

対策

-n オプションを使う

-n, --no-dereference
       treat  LINK_NAME  as a normal file if it is a symbolic link to a
       directory

なので上書きしたい時は何も考えずに ln -snf としておくと良いでしょう。
忘れそうなら alias ln='ln -n' とか .bashrc にでも書いておけばオッケーです d( ´ー `)

参考

linux - how to overwrite symblic link of directory? - Super User
http://superuser.com/questions/645842/how-to-overwrite-symblic-link-of-directory

29
21
1

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
29
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?