How to Use chown Command in Linux: Change File Ownership
The
chown command in Linux changes the owner and optionally the group of a file or directory. Use chown owner[:group] filename to set ownership, where owner is the new user and group is optional.Syntax
The basic syntax of the chown command is:
chown [OPTIONS] OWNER[:GROUP] FILE...
OWNER is the new user who will own the file.
GROUP is optional and sets the group ownership.
FILE is the file or directory to change ownership of.
Options like -R apply changes recursively to directories.
bash
chown [OPTIONS] OWNER[:GROUP] FILE...
Example
This example changes the owner of example.txt to user alice and the group to staff. It shows how to use chown with both owner and group.
bash
touch example.txt ls -l example.txt sudo chown alice:staff example.txt ls -l example.txt
Output
-rw-r--r-- 1 currentuser currentgroup 0 date example.txt
-rw-r--r-- 1 alice staff 0 date example.txt
Common Pitfalls
Common mistakes include:
- Not using
sudowhen you lack permission to change ownership. - Forgetting to specify the group if you want to change it, or using a colon
:incorrectly. - Using
chownon symbolic links without-hoption, which changes the target file instead.
Always check ownership with ls -l after running chown.
bash
sudo chown bob example.txt
# Changes owner only
sudo chown bob: example.txt
# Changes owner and sets group to bob's default groupQuick Reference
| Command | Description |
|---|---|
| chown alice file.txt | Change owner to alice |
| chown alice:staff file.txt | Change owner to alice and group to staff |
| chown -R alice:staff /folder | Change owner and group recursively in /folder |
| chown -h bob symlink | Change owner of the symlink itself, not the target |
Key Takeaways
Use
chown owner[:group] file to change file ownership and optionally group.You need proper permissions or
sudo to change ownership.Use
-R to apply changes recursively to directories.Check ownership changes with
ls -l after running chown.Be careful with symbolic links; use
-h to change the link itself.