chown
Change the owner and group of a file or folder
What it does
chown hands a file to another user: who first, then what. user:group changes both the owner and the group at once, :group only the group. Only root can change owners, so the command runs with sudo.
A typical case is site files uploaded as your own user: the web server on Ubuntu runs as www-data and cannot write to them until you make it the owner. -R changes a folder and everything inside.
Careful. sudo chown -R with a wrong path can change the owner of system files, and the server stops working properly. Check the path before you run it.
Syntax
sudo chown <user>:<group> <file>
sudo chown -R <user>:<group> <folder>Examples
Make www-data the owner and group of /var/www/shop and everything inside
sudo chown -R www-data:www-data /var/www/shopsame as:
sudo chown --recursive www-data:www-data /var/www/shopchown— change the owner-R— recursivelywww-data:www-data— user:group/var/www/shop— the site folder