chown

Change file owner and/or group.

Syntax 
      chown [-fhv] [-R [-H | -L | -P]] owner[:group] file ...

      chown [-fhv] [-R [-H | -L | -P]] :group file ...

Options

   -R         Recurse: Change the mode of file hierarchies rooted in the files
              instead of just the files themselves.

   -R -H      Follow symbolic links on the command line
              (by default Symbolic links within the tree are not followed.)	       
   -R -L      All symbolic links are followed.
   -R -P      No symbolic links are followed. (default)
	     
   -f         Do not display a diagnostic message if chmod could not modify the
              mode for file.

   -h         If the file is a symbolic link, change the mode of the link
              itself rather than the file that the link points to.

   -v         Verbose, show filenames as the mode is modified*

The owner and group operands are both optional; however, at least one must be specified. If the group operand is specified, it must be preceded by a colon (:)

* The -v option is non-standard and its use in scripts is not recommended.

The ownership of a file may only be altered by a super-user for obvious security reasons.

Notes

Previous versions of the chown utility used the dot (.) character to distinguish the group name. This has been changed to be a colon (:) character so that user and group names may contain the dot character.

The -v option is non-standard and its use in scripts is not recommended.

The owner/group may be either a numeric ID or a name. If a user/group name is also a numeric user ID, the operand is used as a user name.

chown exits 0 on success, and >0 if an error occurs.

Examples

Assign Ursula as the owner of "MyFile.txt" file in the Shared directory.

$ sudo chown Ursula /Users/Shared/MyFile.txt

Assign Ursula as the owner, and staff as the group for everything in the "tmp" folder

$ sudo chown -R Ursula:staff /Users/Shared/tmp/

Reset the permissions on the entire home folder for the currently logged in user ($USER) this will reset the user ID number (UID) for all files. POSIX file permissions only use the UID, not the UserName or GUID.

$ sudo chown -R $USER ~$USER

“I never, ever say “I can't" about anything. I might say “I don't have the authority to make that decision” or “Building A is too heavy for me to lift” or "I will need training before I pilot that space shuttle” - Mike Huber

Related:

chflags - Change a file or folder's flags.
chgrp - Change group ownership
chmod - Change access permissions
umask - Users file creation mask


© Copyright SS64.com 1999-2014
Some rights reserved