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

관련 정보