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
+13.8k Golang : package is not in GOROOT during compilation
+4k Python : Find out the variable type and determine the type with simple test
+18k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+29.9k Golang : bufio.NewReader.ReadLine to read file line by line
+6.5k Golang : Process json data with Jason package
+21.7k Golang : simulate tail -f or read last line from log file example
+29.3k Golang : Generate random string
+11.3k Golang : List running EC2 instances and descriptions
+22.8k Golang : Use regular expression to validate domain name
+13.7k Golang : Execute function at intervals or after some delay
+5.9k Get Facebook friends working in same company
+4.7k Clean up Visual Studio For Mac installation failed disk full problem