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.2k Golang : Handle sub domain with Gin
+6.9k Swift : substringWithRange() function example
+21.4k Golang : How to force compile or remove object files first before rebuild?
+14k Golang : Human readable time elapsed format such as 5 days ago
+17k Golang : Read integer from file into array
+8.3k Golang : Find relative luminance or color brightness
+16.8k Golang : Gzip file example
+7.2k Golang : Array mapping with Interface
+6k AWS S3 : Prevent Hotlinking policy
+25.8k Golang : How to write CSV data to file
+7k Golang : Calculate BMI and risk category
+12.2k Golang : Split strings into command line arguments