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
+16.7k Golang : Get command line arguments
+16.1k Golang : When to use init() function?
+5.8k CloudFlare : Another way to get visitor's real IP address
+15.6k Golang : Capture stdout of a child process and act according to the result
+33.7k Golang : Save image to PNG, JPEG or GIF format.
+9.7k Golang : Generate random elements without repetition or duplicate
+10k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+21.7k Golang : Gorilla mux routing example
+5.7k Get Facebook friends working in same company
+10.5k CodeIgniter : Import Linkedin data
+6.5k Golang : Handling Yes No Quit query input
+12.7k How to automatically restart your crashed Golang server