January 2018
Intermediate to advanced
340 pages
8h 6m
English
If you own a file or have the right privileges, you can change the ownership, timestamp, and permissions. A set of functions are provided by the standard library. They are given here:
The following example demonstrates how to use these functions to alter the metadata of a file:
package main import ( "log" "os" "time" ) func main() { // Change permissions using Linux style err := os.Chmod("test.txt", 0777) if err != nil { log.Println(err) } // Change ownership err = os.Chown("test.txt", os.Getuid(), os.Getgid()) if err != nil { log.Println(err) } // Change timestamps twoDaysFromNow := time.Now().Add(48 * time.Hour) lastAccessTime := twoDaysFromNow lastModifyTime ...Read now
Unlock full access