chownx
Change file owner and group.
Mirrors GNU chown. Run it as chownx, or as gnux chownx.
Synopsis
chownx [OPTION]... [OWNER][:[GROUP]] FILE...GNU reference
Description
chownx changes the owner and/or group of each FILE. OWNER and GROUP are names or numeric IDs: 'OWNER' changes the owner only, 'OWNER:GROUP' both, 'OWNER:' the owner and the group to OWNER's login group, and ':GROUP' the group only; an empty spec changes nothing but still checks that each FILE exists. --reference=RFILE takes the owner and group from RFILE instead, and then every operand is a FILE. --from=CURRENT_OWNER:CURRENT_GROUP changes only the files currently owned as stated (either part may be omitted). A symbolic link given as a FILE is followed, and its referent changed, unless -h is given; when both -h and --dereference are given, -h wins. -R changes directory trees, following no symbolic link by default (-P); -H follows the ones given on the command line and -L every one, and when several are given the most cautious wins (-P, then -H, then -L). -c reports each change, -v every file, and -f suppresses most error messages. Unlike GNU chown, which leaves the safeguard off unless --preserve-root is given, chownx refuses to work recursively on '/' unless --no-preserve-root is given; when both are given, --preserve-root wins. On Windows, which has no Unix owners, every change fails with 'Operation not supported'. On a terminal, gnux's terminal view colors the -v report: the verb (removed, created, renamed), each quoted name and the arrows, in the theme --theme or GNUX_THEME names; the words are GNU's, and piped or redirected output is never colored (--pretty=never or GNUX_PRETTY=never turns it off).
Permissions
Changing a file's owner requires root (or CAP_CHOWN). Without it, the owner of a file may change its group, but only to a group they belong to. Search permission is needed on the directories leading to each FILE, and with -R read and search permission on every directory in the tree.
Use cases
- Handing files created as root back to the user
whowill maintain them. - Giving a service account ownership of its data directory with
-R. - Fixing ownership after copying files between machines or containers.
- Changing only the files still owned by a departed user with
--from. - Copying the ownership of one file onto others with
--reference.
Flags
-c, --changes like verbose but report only when a change is made
--dereference affect the referent of each symbolic link (this is the default), rather than the symbolic link itself
-L, --dereference-all with -R, traverse every symbolic link to a directory encountered
-H, --dereference-args with -R, follow symbolic links to directories given on the command line
--from CURRENT_OWNER:CURRENT_GROUP change the ownership of each file only if its current owner and/or group match those specified here; either may be omitted (CURRENT_OWNER:CURRENT_GROUP)
--help display this help and exit
-h, --no-dereference affect symbolic links instead of any referenced file
--no-preserve-root do not treat '/' specially
-P, --physical with -R, do not traverse any symbolic links (default)
--preserve-root fail to operate recursively on '/' (the default)
--pretty WHEN[="always"] the gnux terminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default
--quiet same as --silent
-R, --recursive operate on files and directories recursively
--reference RFILE use RFILE's ownership rather than specifying values
-f, --silent suppress most error messages
--theme NAME color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default
-v, --verbose output a diagnostic for every file processed
--version output version information and exitExamples
Give a file to another user
sudo chownx alice report.txtChange the owner and group
sudo chownx alice:staff report.txtChange only the group
chownx :staff report.txtUse the owner's login group
sudo chownx alice: report.txtUse numeric IDs
sudo chownx 1000:1000 data.dbChange a whole directory tree
sudo chownx -R www-data:www-data /var/www/siteChange a symbolic link itself
sudo chownx -h alice linkChange only the files a departed user still owns
sudo chownx -R --from=bob alice /srv/sharedCopy the ownership of another file
sudo chownx --reference=template.conf new.confReport only the files that changed
sudo chownx -c -R alice project/Change ownership in the portable gnux shell
sudo gnux shell -c 'chownx -R alice:staff project && lsx -l project'Options
Each option has a page of its own, with its usage and examples.
- -c, --changes: Like verbose but report only when a change is made.
- --dereference: Affect the referent of each symbolic
link(this is the default), rather than the symboliclinkitself. - -L, --dereference-all: With
-R, traverse every symboliclinkto a directory encountered. - -H, --dereference-args: With
-R, follow symbolic links to directories given on the command line. - --from: Change the ownership of each file only if its current owner and/or group match those specified here; either may be omitted (CURRENT_OWNER:CURRENT_GROUP).
- -h, --no-dereference: Affect symbolic links instead of any referenced file.
- --no-preserve-root: Do not treat '/' specially.
- -P, --physical: With
-R, do not traverse any symbolic links (default). - --preserve-root: Fail to operate recursively on '/' (the default).
- --pretty: The
gnuxterminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default. - --quiet: Same as
--silent. - -R, --recursive: Operate on files and directories recursively.
- --reference: Use RFILE's ownership rather than specifying values.
- -f, --silent: Suppress most error messages.
- --theme: Color the view with the built-in theme NAME (
gnuxtheme picks and saves one); GNUX_THEME sets the default. - -v, --verbose: Output a diagnostic for every file processed.
Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake |
Help in the terminal
chownx --help # options, first examples, exit status
gnux help chownx # this page: the full manual
gnux help chownx --OPTION # one option in depth, with its examples