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:
For example, to change the owner of a file to someuser
, use the following command:
In the above example, a group is not specified, so the group will remain unchanged. To change the group as well, use the following command:
To operate recursively on a directory, use the -R
flag:
This 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.