{
    "mode": "info",
    "parameter": "chown",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/chown/json",
    "generated": "2026-11-10T05:23:39Z",
    "sections": {
        "File: coreutils.info,  Node: chown invocation,  Next: chgrp invocation,  Up: Changing file attributes": {
            "content": "",
            "subsections": [
                {
                    "name": "13.1 'chown': Change file owner and group",
                    "content": "'chown' changes the user and/or group ownership of each given FILE to\nNEW-OWNER or to the user and group of an existing reference file.\nSynopsis:\n\nchown [OPTION]... {NEW-OWNER | --reference=REFFILE} FILE...\n\nIf used, NEW-OWNER specifies the new owner and/or group as follows\n(with no embedded white space):\n\n[OWNER] [ : [GROUP] ]\n\nSpecifically:\n"
                }
            ]
        },
        "OWNER": {
            "content": "If only an OWNER (a user name or numeric user ID) is given, that\nuser is made the owner of each given file, and the files' group is\nnot changed.\n\nOWNER':'GROUP\nIf the OWNER is followed by a colon and a GROUP (a group name or\nnumeric group ID), with no spaces between them, the group ownership\nof the files is changed as well (to GROUP).\n\nOWNER':'\nIf a colon but no group name follows OWNER, that user is made the\nowner of the files and the group of the files is changed to OWNER's\nlogin group.\n\n':'GROUP\nIf the colon and following GROUP are given, but the owner is\nomitted, only the group of the files is changed; in this case,\n'chown' performs the same function as 'chgrp'.\n\n':'\nIf only a colon is given, or if NEW-OWNER is empty, neither the\nowner nor the group is changed.\n\nIf OWNER or GROUP is intended to represent a numeric user or group\nID, then you may specify it with a leading '+'.  *Note Disambiguating\nnames and IDs::.\n\nSome older scripts may still use '.' in place of the ':' separator.\nPOSIX 1003.1-2001 (*note Standards conformance::) does not require\nsupport for that, but for backward compatibility GNU 'chown' supports\n'.' so long as no ambiguity results, although it issues a warning and\nsupport may be removed in future versions.  New scripts should avoid the\nuse of '.' because it is not portable, and because it has undesirable\nresults if the entire OWNER'.'GROUP happens to identify a user whose\nname contains '.'.\n\nIt is system dependent whether a user can change the group to an\narbitrary one, or the more portable behavior of being restricted to\nsetting a group of which the user is a member.\n\nThe 'chown' command sometimes clears the set-user-ID or set-group-ID\npermission bits.  This behavior depends on the policy and functionality\nof the underlying 'chown' system call, which may make system-dependent\nfile mode modifications outside the control of the 'chown' command.  For\nexample, the 'chown' command might not affect those bits when invoked by\na user with appropriate privileges, or when the bits signify some\nfunction other than executable permission (e.g., mandatory locking).\nWhen in doubt, check the underlying system behavior.\n\nThe program accepts the following options.  Also see *note Common\noptions::.\n\n'-c'\n'--changes'\nVerbosely describe the action for each FILE whose ownership\nactually changes.\n\n'-f'\n'--silent'\n'--quiet'\nDo not print error messages about files whose ownership cannot be\nchanged.\n\n'--from=OLD-OWNER'\nChange a FILE's ownership only if it has current attributes\nspecified by OLD-OWNER.  OLD-OWNER has the same form as NEW-OWNER\ndescribed above.  This option is useful primarily from a security\nstandpoint in that it narrows considerably the window of potential\nabuse.  For example, to reflect a user ID numbering change for one\nuser's files without an option like this, 'root' might run\n\nfind / -owner OLDUSER -print0 | xargs -0 chown -h NEWUSER\n\nBut that is dangerous because the interval between when the 'find'\ntests the existing file's owner and when the 'chown' is actually\nrun may be quite large.  One way to narrow the gap would be to\ninvoke chown for each file as it is found:\n\nfind / -owner OLDUSER -exec chown -h NEWUSER {} \\;\n\nBut that is very slow if there are many affected files.  With this\noption, it is safer (the gap is narrower still) though still not\nperfect:\n\nchown -h -R --from=OLDUSER NEWUSER /\n\n'--dereference'\nDo not act on symbolic links themselves but rather on what they\npoint to.  This is the default when not operating recursively.\n\nCombining this dereferencing option with the '--recursive' option\nmay create a security risk: During the traversal of the directory\ntree, an attacker may be able to introduce a symlink to an\narbitrary target; when the tool reaches that, the operation will be\nperformed on the target of that symlink, possibly allowing the\nattacker to escalate privileges.\n\n'-h'\n'--no-dereference'\nAct on symbolic links themselves instead of what they point to.\nThis mode relies on the 'lchown' system call.  On systems that do\nnot provide the 'lchown' system call, 'chown' fails when a file\nspecified on the command line is a symbolic link.  By default, no\ndiagnostic is issued for symbolic links encountered during a\nrecursive traversal, but see '--verbose'.\n\n'--preserve-root'\nFail upon any attempt to recursively change the root directory,\n'/'.  Without '--recursive', this option has no effect.  *Note\nTreating / specially::.\n\n'--no-preserve-root'\nCancel the effect of any preceding '--preserve-root' option.  *Note\nTreating / specially::.\n\n'--reference=REFFILE'\nChange the user and group of each FILE to be the same as those of\nREFFILE.  If REFFILE is a symbolic link, do not use the user and\ngroup of the symbolic link, but rather those of the file it refers\nto.\n\n'-v'\n'--verbose'\nOutput a diagnostic for every file processed.  If a symbolic link\nis encountered during a recursive traversal on a system without the\n'lchown' system call, and '--no-dereference' is in effect, then\nissue a diagnostic saying neither the symbolic link nor its\nreferent is being changed.\n\n'-R'\n'--recursive'\nRecursively change ownership of directories and their contents.\n\n'-H'\nIf '--recursive' ('-R') is specified and a command line argument is\na symbolic link to a directory, traverse it.  *Note Traversing\nsymlinks::.\n\n'-L'\nIn a recursive traversal, traverse every symbolic link to a\ndirectory that is encountered.\n\nCombining this dereferencing option with the '--recursive' option\nmay create a security risk: During the traversal of the directory\ntree, an attacker may be able to introduce a symlink to an\narbitrary target; when the tool reaches that, the operation will be\nperformed on the target of that symlink, possibly allowing the\nattacker to escalate privileges.\n\n*Note Traversing symlinks::.\n\n'-P'\nDo not traverse any symbolic links.  This is the default if none of\n'-H', '-L', or '-P' is specified.  *Note Traversing symlinks::.\n\nAn exit status of zero indicates success, and a nonzero value\nindicates failure.\n\nExamples:\n\n# Change the owner of /u to \"root\".\nchown root /u\n\n# Likewise, but also change its group to \"staff\".\nchown root:staff /u\n\n# Change the owner of /u and subfiles to \"root\".\nchown -hR root /u\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}