FreeBSDのlnコマンドで-Fオプションの用途は何ですか?

FreeBSDのlnコマンドで-Fオプションの用途は何ですか?

存在するhttps://www.freebsd.org/cgi/man.cgi?ln、それは言う

       -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 neither -f nor -i is specified, -f is
       implied.  The -F option is a no-op unless -s is specified.

では、このオプションをどのように使用しますか?ファイルをディレクトリにリンクすると、そのディレクトリに同じ名前のリンクが作成されます。

ベストアンサー1

言ったように、ターゲットファイルがすでに存在し、ディレクトリの場合はlnリンクが発生するように削除されます。

mkdir dir1
echo hello >file
ln -s file dir1     # Creates a broken symlink at dir1/file pointing to itself

cat dir1/file
cat: dir1/file: Too many levels of symbolic links

mkdir dir2
echo hello >file
ln -Fs file dir2    # Removes dir1 and creates a symlink of dir1 pointing to file

cat dir2/file
cat: dir2/file: Not a directory

cat dir2
hello

おすすめ記事