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
+10.5k Golang : Get remaining text such as id or filename after last segment in URL path
+13.5k Golang : Execute function at intervals or after some delay
+17.7k Golang : Calculate entire request body length during run time
+13.7k nginx: [emerg] unknown directive "ssl"
+7.3k Golang : How to check variable or object type during runtime?
+18.5k Golang : How to count the number of repeated characters in a string?
+8.8k Golang : Test a slice of integers for odd and even numbers
+6.7k Golang : Reverse a string with unicode
+18.9k Nginx + FastCGI + Go Setup.
+5k Golang : Function as an argument type example
+13.7k Golang : Get all local users and print out their home directory, description and group id
+10.5k CodeIgniter : Import Linkedin data