chown – change file owner and group

chown changes the owner and/or group of files and directories. Requires root privileges to change ownership to another user.
Synopsis
chown [OPTIONS] [OWNER][:GROUP] FILE...
Common Options
| Option | Description |
|---|---|
-R | Recursive (apply to directories and contents) |
-v | Verbose, show files being changed |
-c | Report only when changes are made |
--reference=FILE | Copy ownership from another file |
-h | Change symlink owner (not target) |
Examples
Change owner
$ chown greys file.txt
$ ls -l file.txt
-rw-r--r-- 1 greys staff 1024 Jan 15 10:00 file.txt
Change owner and group
$ chown greys:developers file.txt
$ ls -l file.txt
-rw-r--r-- 1 greys developers 1024 Jan 15 10:00 file.txt
Change group only
$ chown :www-data file.txt
# Or use chgrp
$ chgrp www-data file.txt
Recursive change
$ chown -R www-data:www-data /var/www/html/
Verbose output
$ chown -v greys:staff *.txt
changed ownership of 'file1.txt' to greys:staff
changed ownership of 'file2.txt' to greys:staff
Copy ownership from another file
$ chown --reference=goodfile.txt badfile.txt
Change symlink ownership
$ chown -h greys symlink # Changes symlink, not target
Common Patterns
Web server files
$ sudo chown -R www-data:www-data /var/www/
$ sudo chmod -R 755 /var/www/
Fix home directory permissions
$ sudo chown -R greys:greys /home/greys/
Shared directory for group
$ sudo chown :developers /shared/
$ sudo chmod 2775 /shared/ # setgid for new files
Understanding Ownership
$ ls -l file.txt
-rw-r--r-- 1 greys staff 1024 Jan 15 10:00 file.txt
│ │
│ └── Group
└── Owner (user)
Find files by owner
$ find /home -user olduser
$ find /var -group www-data
Tips
- Need sudo: Regular users can’t change files to other owners
- Check first:
ls -lto see current ownership before changing - Web files: Usually
www-data:www-dataon Debian/Ubuntu - Preserve group: Use
chown user:to keep current group - Numeric IDs:
chown 1000:1000 file.txtworks across systems
See Also
Related Commands
- chmod — Change file permissions
- chgrp — Change group only
- ls — List ownership with
ls -l - stat — Detailed file information






