How to use the chown command in Linux?

The chown command is used to change the owner and group of a file or directory.

The basic syntax of the chown command is as follows:

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

Common options include:

  1. R: Recursively change the owner and group of files or directories.
  2. -f: suppress error output.
  3. -v: Display detailed modification information.

Here are some examples of using the chown command:

  1. Change the owner of the file to “root” and the group to “admin”.
chown root:admin file.txt
  1. Recursively change the owner of all files and directories in the directory and its subdirectories to “user” and the group to “group”.
chown -R user:group directory/
  1. Change the owner of the file to the current user.
chown $USER file.txt
  1. Change the owner and group of the file to the primary group of the current user.
chown $USER: file.txt

Attention: When using the chown command, only the root user or the owner of the file/directory can modify their owner and group ownership.

Leave a Reply 0

Your email address will not be published. Required fields are marked *