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.4k Golang : How to check if a string with spaces in between is numeric?
+12.8k Golang : Pass database connection to function called from another package and HTTP Handler
+8k Javascript : How to check a browser's Do Not Track status?
+7.2k Nginx : How to block user agent ?
+9.7k Javascript : Read/parse JSON data from HTTP response
+18k Golang : Iterate linked list example
+31.9k Golang : Get local IP and MAC address
+8.2k Golang : Multiplexer with net/http and map
+7.2k Golang : Validate credit card example
+4.5k Golang : Valued expressions and functions example
+5.9k Get website traffic ranking with Similar Web or Alexa
+16.5k Golang :Trim white spaces from a string