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:
- R: Recursively change the owner and group of files or directories.
- -f: suppress error output.
- -v: Display detailed modification information.
Here are some examples of using the chown command:
- Change the owner of the file to “root” and the group to “admin”.
chown root:admin file.txt
- 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/
- Change the owner of the file to the current user.
chown $USER file.txt
- 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.