Jump to content

chown

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 131.215.220.161 (talk) at 23:27, 24 April 2016 (only root and owner can change file permissions (see). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


The chown command (abbreviation for change owner) is used on Unix-like systems to change the owner of a file system object (files and directories). Unprivileged (regular) users who wish to change the group of a file that they own may use chgrp.

From the BSD man page for chown:

For obvious security reasons, the ownership of a file may only be altered by a super-user. Similarly, only a member of a group can change a file's group ID to that group.[1]

Usage examples

These examples illustrate typical syntax and use. Modifying permissions requires you are either root or own a file. Changing owner requires root privilege.

  • Change the owner of /var/run/httpd.pid to 'root' (the standard name for the Superuser).
 $ chown root /var/run/httpd.pid
  • Change the owner of strace.log to 'rob' and the group identifier to 'developers'.
 $ chown rob:developers strace.log
  • Change the owner of /tmp and /var/tmp to ‘nobody’ (not a good idea), and change the group of /tmp and /var/tmp to ‘nogroup
 $ chown nobody:nogroup /tmp /var/tmp
  • Change the group identifier of /home to 512 (regardless of whether a group name is associated with the identifier 512 or not).
 $ chown :512 /home
  • Change the ownership of base to the user foouser and make it recursive (-R)
 $ chown -R foouser base
  • Change the ownership to newuser and group to newgroup for all of the files and directories in current directory, and all subdirectories (recursively).
 $ chown -R newuser:newgroup .
  • To verify that the owner or group has been changed, type
    ls -l
    
    to see who owns a file and what group it's part of (i.e. the 3rd and 4th columns respectively).

References

See also