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
+34.4k Golang : Create x509 certificate, private and public keys
+15.8k Golang : How to convert(cast) IP address to string?
+11.6k Golang : Handle API query by curl with Gorilla Queries example
+9.1k Golang : Populate or initialize struct with values example
+9.3k Golang : Get curl -I or head data from URL example
+6.2k Fontello : How to load and use fonts?
+8.9k Golang : How to join strings?
+16.7k Golang : Execute terminal command to remote machine example
+12.9k Golang : Pass database connection to function called from another package and HTTP Handler
+21.7k Curl usage examples with Golang
+3.9k Java : Random alphabets, alpha-numeric or numbers only string generator
+11.3k Golang : Roll the dice example