A popular topic in UNIX systems programming is UNIX file permissions. In this section, you will learn how to print the permissions of any file, provided that you have the required UNIX permission to do so. The name of the program is permissions.go, and it will be presented in three parts.
The first part of permissions.go contains the following Go code:
package main import ( "fmt" "os" )
The second code segment of permissions.go is shown in the following Go code:
func main() { arguments := os.Args if len(arguments) == 1 { fmt.Printf("usage: permissions filename\n") return }
The last part of this utility follows:
filename := arguments[1] info, _ := os.Stat(filename) mode := info.Mode() fmt.Println(filename, "mode is", mode.String()[1:10]) }
The call to os...