Reprint
This article is transcoded by SimpRead, original address www.runoob.com
Linux chown command Linux command collection Linux chown (full English spelling: change owner) command is used to set the file owner and file associated group.
Linux chown (full English spelling: change owner) command is used to set the file owner and associated group.
Linux/Unix is a multi-user multi-tasking operating system, and all files have owners. Using chown to change the owner of a specified file to a specified user or group, the user can be the username or user ID, the group can be the group name or group ID, and the files are a list of files separated by spaces whose permissions to change are supported with wildcards.
chown requires superuser root privileges to execute this command.
Only superusers and the file owner of the group can change the associated group of the file. Non-superusers may need to use the chgrp command to set the associated group.
Permission required: root
Syntax
chown [-cfhvR] [--help] [--version] user[:group] file...
Parameters:
- user: the user ID of the new file owner
- group: the user group (group) of the new file owner
- -c: show information about the changes made
- -f: suppress error messages
- -h: affect symbolic links
- -v: show verbose processing information
- -R: operate on files in the specified directory and all its subdirectories recursively
- –help: display help
- –version: display version
Examples
Set the owner of /var/run/httpd.pid to root:
chown root /var/run/httpd.pid
Set the owner of the file file1.txt to runoob, and the group to runoobgroup:
chown runoob:runoobgroup file1.txt
Set the owner and group of all files and subdirectories in the current directory to runoob and runoobgroup respectively:
chown -R runoob:runoobgroup *
Set the associated group of /home/runoob to 512 (group ID) without changing the owner:
chown :512 /home/runoob
More content
See
man chown