$linuxjunkies
>

chown(1)

Change the owner and/or group of files or directories.

UbuntuDebianFedoraArch

Synopsis

chown [OPTION]... [OWNER][:[GROUP]] FILE...

Description

chown changes the user and/or group ownership of each file. OWNER may be either a user name or numeric user ID (UID). GROUP may be either a group name or numeric group ID (GID). If only OWNER is given, that user becomes the owner and the group is unchanged. If OWNER:GROUP is given, both are changed. If only :GROUP is given, only the group is changed.

By default, chown does not follow symbolic links. Use -h to change the target of a symlink itself, or -L to follow symlinks when recursing directories.

Common options

FlagWhat it does
-R, --recursiveRecursively change ownership of all files and directories within a directory tree
-HFollow symbolic links on the command line when used with -R
-LFollow all symbolic links when used with -R
-PNever follow symbolic links (default behavior with -R)
-h, --no-dereferenceChange the owner of symbolic links themselves, not their targets
-v, --verbosePrint the name of each file whose ownership changes
-c, --changesLike verbose, but only report files that actually change
--reference=FILEChange ownership to match the specified reference file instead of using OWNER:GROUP
-f, --silent, --quietSuppress error messages about permission denied and similar errors

Examples

Change the owner of file.txt to alice, group remains unchanged

chown alice file.txt

Change owner to alice and group to staff for file.txt

chown alice:staff file.txt

Change only the group to staff, leaving the owner unchanged

chown :staff file.txt

Recursively change owner and group of all files in /home/project directory

chown -R alice:staff /home/project

Change the owner of the symlink itself, not its target

chown -h alice symlink.txt

Change ownership and report only files that actually changed

chown -c alice file1 file2 file3

Change myfile.txt to have the same owner and group as template.txt

chown --reference=template.txt myfile.txt

Recursively change all files to UID 1000 and GID 1000 (by numeric ID)

chown -R 1000:1000 /home/newuser

Related commands