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.3k Golang : Sort and reverse sort a slice of bytes
+15.7k Golang : Find file size(disk usage) with filepath.Walk
+7.8k Golang : Get final balance from bit coin address example
+23.2k Golang : GORM read from database example
+6.8k Golang : Error reading timestamp with GORM or SQL driver
+7.9k Golang : Apply Histogram Equalization to color images
+17.7k Golang : convert int to string
+22.8k Golang : How to validate URL the right way
+20.8k Golang : Securing password with salt
+16.9k Golang : Get download file size
+6k Golang : How to detect if a sentence ends with a punctuation?
+9.8k Golang : Web routing/multiplex example