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
+6.5k Golang : Humanize and Titleize functions
+5.7k nginx : force all pages to be SSL
+10.2k Golang : Create matrix with Gonum Matrix package example
+10.3k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+18.2k Golang : Iterating Elements Over A List
+11.8k Golang : Get remaining text such as id or filename after last segment in URL path
+5.3k Unix/Linux : How to find out the hard disk size?
+14k Golang : Recombine chunked files example
+17.1k Golang : Linked list example
+14.4k Golang : Find commonalities in two slices or arrays example
+13.7k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+11.7k Golang : Convert a rune to unicode style string \u