Unix-commands-chown

提供:Dev Guides
移動先:案内検索

chown-Unix、Linuxコマンド

NAME

*chown* -所有者を変更するには、指定された各ファイルのユーザーまたはグループの所有権を新しい所有者に変更します。 Chownは、既存の参照ファイルのユーザー/グループに一致するようにファイルの所有権を変更することもできます。

概要

chown [Options]... NewOwner File...
chown [Options]... :Group File...
chown [Options]... --reference=RFILE File...

説明

NewOwnerを使用する場合、次のように新しい所有者またはグループ、あるいはその両方を指定します(埋め込み空白なし):

chown [OWNER] [ [:.] [GROUP] ]

所有者/グループを指定する方法の例を次に示します。

  • OWNER(ユーザー名または数値のユーザーID)のみが指定されている場合、そのユーザーは指定された各ファイルの所有者になり、ファイルのグループは変更されません。
chown OWNER
  • OWNERの後にコロンまたはドットとGROUP(グループ名または数値グループID)が続き、それらの間にスペースがない場合、ファイルのグループ所有権も(GROUPに)変更されます。
chown OWNER.GROUP
chown OWNER:GROUP
  • OWNERの後にグループ名がないコロンまたはドットがある場合、そのユーザーがファイルの所有者になり、ファイルのグループがOWNERのログイングループに変更されます。
chown OWNER.
chown OWNER:
  • コロンまたはドットとそれに続くGROUPが指定されていて、所有者が省略されている場合、ファイルのグループのみが変更されます。この場合、「chown」は「chgrp」と同じ機能を実行します。
chown .GROUP
chown :GROUP

オプション

Tag Description
-c—​changes Verbosely describe the action for each File whose ownership actually changes.
--dereference Do not act on symbolic links themselves but rather on what they point to.
-f—​silent—​quiet Do not print error messages about files whose ownership cannot be changed.
-h—​no-dereference Act on symbolic links themselves instead of what they point to. This is the default. This mode relies on the 'lchown' system call. On systems that do not provide the 'lchown' system call, 'chown' fails when a file specified on the command line is a symbolic link. By default, no diagnostic is issued for symbolic links encountered during a recursive traversal, but see '--verbose'.
--reference=FILE Use the user and group of the reference FILE instead of an explicit NewOwner value.
-R—​recursive Recursively change ownership of directories and their contents.
-v—​verbose Verbosely describe the action (or non-action) taken for every FILE. If a symbolic link is encountered during a recursive traversal on a system without the 'lchown' system call, and '--no-dereference' is in effect, then issue a diagnostic saying neither the symbolic link nor its referent is being changed.

ファイルの所有者を変更します。

$ chown user1 sample.txt

ファイルのグループを変更します。

$ chown :mygroup file.txt

単一のコマンドでファイルの所有者とグループの両方を変更します。

$ chown user1:mygroup file.txt

link:/cgi-bin/printpage.cgi [__印刷]