How ownership works
Every Linux file has an owner (user) and a group. They decide who can read, change or run it. See them with ls -l:
-rwxr-xr-- 1 karim devs file.txt
rwxare the rights of the owner (karim).r-xare the rights of the group (devs).r--are the rights of everyone else.
Ownership works together with chmod, which sets the read, write and run rights.

Syntax
chown [options] new_user[:new_group] target
Add :group after the user to change the group too.
Recursive change with -R
-R makes chown walk through all folders and files below the target:
sudo chown -R karim:devs /srv/www

Every item inside /srv/www now belongs to karim and the group devs.
By default, chown -R does not follow symbolic links. Two options change that:
sudo chown -RH karim /srv/www
sudo chown -RL karim /srv/www

-H follows a link given on the command line. -L follows every link. Use them with care, because a link can lead outside the folder.
Safety first
- Back up before a big change:
rsync -a /var/www /backup/

- Test the change with a dry run:
chown --dry-run -v -R karim:devs /path

- Large trees with many thousands of files can use a lot of disk I/O. Run them at a quiet time.
Examples
Change the owner only
sudo chown -R karim /opt/app

Change owner and group
sudo chown -R karim:devs /opt/app

Show only the files that change
chown -Rc karim .
Skip a folder, such as .git
find . -path './.git' -prune -o -exec chown karim:devs {} +
Using sudo
You need root rights to give files to someone else. If an admin should do it without a password, add a line like this with visudo:
karim ALL=(ALL) NOPASSWD: /bin/chown
Grant this only when it is needed.
sudo chown -R root /. It can break the whole system. Always double-check the path.Quick recap
chown -R user:group pathchanges a whole tree.- Back up and use
--dry-runfirst. - Be careful with symbolic links and the path.