1

If I were to do it on Linux alone, it'd be easy with the following code:

package main

import (
    "fmt"
    "log"
    "os/exec"
)

func main() {

    err := exec.Command("cp", "-rl", "src/path", "target/path").Run()
    if err != nil {
        log.Fatal(err)
    }
}

However, I am looking for a way to do so in Golang so that it works across different operating systems.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Varo OP
  • 71
  • 6
  • 1
    Some OSes on which Go runs don't have hard links at all, so you must use OS-dependent code here. You can use `os.Link` and check for errors; to avoid being overly OS dependent, you can just assume that any error means "not supported here, perhaps because of cross-device-link, perhaps just generally unsupported". – torek Aug 06 '22 at 00:31

0 Answers0