Golang : Change file read or write permission example
Problem :
You have a file and you need to change a file read, write or execute permission. How to achieve that?
Solutions :
Example 1:
// use Exec() function
cmd := exec.Command("chmod", "666", "file.txt")
out, err := cmd.Output()
Example 2:
// use os.Chmod() function.
err := os.Chmod("file.txt", 0777)
if err != nil {
fmt.Println(err)
}
See also : Golang : Test file read write permission example
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+9.1k Golang : Read file and convert content to string
+14.1k Golang : Get digits from integer before and after given position example
+10.7k Golang : Convert(cast) bigint to string
+17.5k Unmarshal/Load CSV record into struct in Go
+5.7k Unix/Linux : How to get own IP address ?
+4.8k List of Golang XML tutorials
+17.8k Golang : Read input from console line
+21k Golang : Read directory content with filepath.Walk()
+42.7k Golang : Use wildcard patterns with filepath.Glob() example
+3.6k Golang : Valued expressions and functions example
+32.7k Golang : Proper way to set function argument default value