About chown command generator
chown changes the owner and group of files. It is often needed after copying files with sudo or deploying an app.
Examples
- chown user file changes the owner.
- chown user:group file changes both.
- chown -R user:group dir applies to everything inside a directory.
Be careful with -R
Recursive changes on the wrong path, such as /, can break a system. Check the path before you run it.
A worked example
After copying a website with sudo, files belong to root and the web server cannot write to them. Fix it with sudo chown -R www-data:www-data /var/www/site. The part before the colon is the user and the part after is the group.
Safety checks
- Double-check the path before using -R.
- Use ls -l first to see the current owner.
- Prefer a dedicated user for each application over using root.
