Golang 之 文件硬连接 与 软连接

it2025-02-14  31

Golang support for native Windows hard links was added in Go 1.4. Specifically, this commit makes the following snippet work:

err := os.Link("original.txt", "link.txt")

Beware that not all Windows file systems support hard links. Currently NTFS and UDF support it, but FAT32, exFAT and the newer ReFS do not.

Full example code:

package main import ( "log" "os" "io/ioutil" ) func main() { err := ioutil.WriteFile("original.txt", []byte("hello world"), 0600) if err != nil { log.Fatalln(err) } err = os.Link("original.txt", "link.txt") if err != nil { log.Fatalln(err) } }

 软连接(symbolic link) 就是把上面硬链接的Link 改成  SymLink

 

最新回复(0)