Linux command(chown)

说明

chown 命令是 Linux 系统中的一个命令,用于修改文件或目录的所有者和所属组。其语法格式如下:

bash
chown [选项] [所有者][:[所属组]] 文件或目录

其中,[选项] 表示可选参数,常用的选项有:

-R:递归修改指定目录及其子目录下的所有文件和目录的所有者和所属组。
-v:显示修改的详细信息。
[所有者] 表示文件或目录的所有者,可以是用户或用户组的名称或 ID。[所属组] 表示文件或目录的所属组,可以是用户组的名称或 ID,如果省略则默认为与文件或目录原来的所属组相同。

文件或目录 表示需要修改所有者和所属组的文件或目录的路径。

例如,将文件 file.txt 的所有者修改为 user1,所属组修改为 group1,可以使用以下命令:

bash
sudo chown user1:group1 file.txt

如果需要递归修改目录 dir 及其子目录下的所有文件和目录的所有者和所属组,可以使用以下命令:

bash
sudo chown -R user1:group1 dir

需要注意的是,chown 命令需要使用管理员权限,因此需要在命令前加上 sudo 前缀。

总之,chown 命令是 Linux 系统中一个重要的命令,用于修改文件或目录的所有者和所属组,可以方便地进行文件管理和共享。

Simply put

The chown command in Linux is used to change the ownership of a file or directory. The syntax for the chown command is as follows:

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

Here, OWNER is the new owner of the file or directory, and GROUP is the new group owner. If GROUP is not specified, it defaults to the primary group of the new owner.

The FILE argument specifies the file or directory whose ownership is to be changed. You can specify multiple files or directories separated by spaces.

Some common options for the chown command are:

  • -R : Recursively change ownership of all files and directories under the specified directory.
  • -v : Verbose output, showing the changes made to each file or directory.
  • -c : Similar to -v , but only shows output for files whose ownership was actually changed.

For example, to change the ownership of a file named example.txt to user john and group users , you would use the following command:

chown john:users example.txt

To recursively change the ownership of all files and directories under a directory named mydir to user john , you would use:

chown -R john mydir

猜你喜欢

转载自blog.csdn.net/weixin_38233104/article/details/130994175