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
+11.4k Golang : Handle API query by curl with Gorilla Queries example
+15.6k Golang : Get digits from integer before and after given position example
+9.5k Golang : Copy map(hash table) example
+15.4k Golang : Validate hostname
+15.6k Golang : How to login and logout with JWT example
+6k Java : Human readable password generator
+5.3k Gogland : Datasource explorer
+14.2k Golang : How to pass map to html template and access the map's elements
+5.9k PHP : Get client IP address
+7.3k Golang : Create zip/ePub file without compression(use Store algorithm)
+25.1k Golang : Generate MD5 checksum of a file
+5.9k Golang : Compound interest over time example