chown
chown is a Linux command-line program that is used to change the owner and group of a file or directory. The syntax is as follows:
chown [OPTIONS] OWNER[:GROUP] FILEFor example, to change the owner of a file to someuser, use the following command:
chown someuser /path/to/fileIn the above example, a group is not specified, so the group will remain unchanged. To change the group as well, use the following command:
chown someuser:somegroup /path/to/fileTo operate recursively on a directory, use the -R flag:
chown -R someuser:somegroup /path/to/directoryThis recursive option is really useful for when shared files (e.g. a volume) have been written to from inside a Docker container, but you want to modify them from the host machine. Docker images typically run as root, so the files will be owned by root. You can use chown to change the owner of the files to your user.
sudo is commonly used in conjunction with chown as the standard user does not normally have permissions to change the owner and/or group.