chown – change file owner and group

chown command
chown command

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

OptionDescription
-RRecursive (apply to directories and contents)
-vVerbose, show files being changed
-cReport only when changes are made
--reference=FILECopy ownership from another file
-hChange 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
$ 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 -l to see current ownership before changing
  • Web files: Usually www-data:www-data on Debian/Ubuntu
  • Preserve group: Use chown user: to keep current group
  • Numeric IDs: chown 1000:1000 file.txt works across systems

See Also

  • chmod — Change file permissions
  • chgrp — Change group only
  • ls — List ownership with ls -l
  • stat — Detailed file information

Tutorials