次のようなリンクを作成する理由:ln -nsf?


42

これは何をしますか?

ln -nsf

ln -sハードリンクではなくシンボリックリンクを作成することは知っています。つまり、削除することができ、リンクしていると思われるものは削除されません。しかし、他のことはどういう意味ですか?(-nf)

更新:大丈夫...だから、コマンドラインからこのようなものを見つけることができることを思い出した。タイピングからわかったことはln --help次のとおりです。

-f, --force                 remove existing destination files
-n, --no-dereference        treat destination that is a symlink to a
                            directory as if it were a normal file

しかし、これが意味するものが何であるかはまだはっきりしていません。なぜこのようなソフト/シンボリックリンクを作成したいのですか?


1
使用しない場合でも-s、元のファイルを削除せずにリンクを削除できます。ハードリンクはファイルのリンク数を増やすため、ファイルへのリンクの1つだけを削除しても削除されません。
逆上

ハードリンクとシンボリックリンクの違いはまったくありません。ハードリンクは、ディスク上の同じバイト(inode)を指します。ソフトリンクは、filenameで別のファイルを指します
グレッグヒューギル

manページもあります。すなわち、man lnを実行します。またはその男、ヘルプシステムについて学ぶために。あなたは...あまりにも、オンラインのmanページを取得することができます
ピーター・コルド

回答:


43

BSD manページから:

 -f    If the target file already exists, then unlink it so that the link
           may occur.  (The -f option overrides any previous -i options.)

 -n    If the target_file or target_dir is a symbolic link, do not follow
           it.  This is most useful with the -f option, to replace a symlink
           which may point to a directory.

32

この-nオプションは(と一緒に-f)強​​制ln的にディレクトリへのシンボリックリンクを更新します。どういう意味ですか?

2つのディレクトリがあるとします

  • foo
  • バー

および既存のシンボリックリンク

  • バズ->バー

今度は、代わりにfooを指すようにbazを更新します。ただやるなら

ln -sf foo baz

あなたは得るだろう

  • baz / foo-> foo
  • baz-> bar(変更なし)、したがって
  • bar / foo-> foo

追加する場合 -n

ln -sfn foo baz

あなたが欲しいものを手に入れます。

  • baz-> foo

つまり、「非参照」とは、既存のリンクを解決してそのディレクトリ内に新しいリンクを配置するのではなく、単に更新することです。


2
最も役立つ答え。
コベジョン

1

lnのすべてのオプションを次に示します。ここに-nと-fがあります。

 -F    If the target file already exists and is a directory, then remove
       it so that the link may occur.
       The -F option should be used with either -f or -i options.  If
       none is specified, -f is implied.
       The -F option is a no-op unless -s option is specified.

 -h    If the target_file or target_dir is a symbolic link, do not
       follow it.  This is most useful with the -f option, to replace 
       a symlink which may point to a directory.

 -f    If the target file already exists, then unlink it so that the
       link may occur.  (The -f option overrides any previous -i options.)

 -i    Cause ln to write a prompt to standard error if the target file
       exists.  If the response from the standard input begins with the
       character `y' or `Y', then unlink the target file so that the link
       may occur.  Otherwise, do not attempt the link.  (The -i option
       overrides any previous -f options.)

 -n    Same as -h, for compatibility with other ln implementations.

 -s    Create a symbolic link.

 -v    Cause ln to be verbose, showing files as they are processed.

-1

「man ln」と入力すると、次のようなものを見つけることができます。

   -f, --force
          remove existing destination files

   -n, --no-dereference
          treat destination that is a symlink to a directory as if it were
          a normal file

20
私はまだそれが何を意味するのか正確に理解していません
アンドリュー

-1

-f、--force既存の宛先ファイルを削除します

-n、--no-dereferenceは、ディレクトリへのシンボリックリンクである宛先を通常のファイルであるかのように扱います


-5

-fは、コマンドのターゲットが既存のファイルである場合、削除して新しいリンクに置き換える必要があることを示します。(Unixの影響を受けるシステムでは、「ファイル」にディレクトリ、リンク、パイプなどを含めることができます。)

-nは-fを変更し、指定したターゲットが既存のシンボリックリンクである場合、削除しないでください。


3
の説明-nが間違っています。-f単独ではディレクトリへのシンボリックリンクを置き換えません。ディレクトリへのシンボリックリンクを置き換える場合-n、既存のシンボリックリンクをディレクトリではなく通常のファイルのように扱うために必要です。
ブライアン
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.