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
+7.4k Golang : Of hash table and hash map
+6.8k Golang : Output or print out JSON stream/encoded data
+5k Unix/Linux : secure copying between servers with SCP command examples
+5.1k Golang : Constant and variable names in native language
+20.4k Golang : Compare floating-point numbers
+7.7k SSL : How to check if current certificate is sha1 or sha2 from command line
+13.3k Golang : How to calculate the distance between two coordinates using Haversine formula
+6.5k CodeIgniter : form input set_value cause " to become & quot
+17k Golang : Read integer from file into array
+10.7k Golang : ISO8601 Duration Parser example
+13k Golang : http.Get example