The chown command in Linux stands for “change owner.” It is used to change the owner and/or group of files or directories.
This command is particularly useful when you need to transfer ownership of files or directories to another user or group, especially when managing permissions and access control.
In the context of web hosting on a Linux server, the chown
command is still used to change ownership of files and directories, but it’s often employed within the context of managing web server files and configurations.
The basic syntax for the chown command is:
chown [OPTIONS] USER[:GROUP] FILE(s)
Here’s what each part of the command does:
USER
: Specifies the new owner of the file or directory.GROUP
: (Optional) Specifies the new group ownership of the file or directory. If omitted, the group ownership will remain unchanged.FILE(s)
: Specifies the file or files for which ownership is to be changed.
Some common options used with chown
include:
-R
or--recursive
: Change ownership recursively for all files and directories within the specified directory.-v
or--verbose
: Output a message for every file processed, indicating the change of ownership.-c
or--changes
: Like-v
, but only output messages when a change is made.
How to Use chown
chown
is a command in Unix-like operating systems, including Linux and macOS, used to change the ownership of files and directories. The command allows you to change both the user owner and the group owner of a file or directory.
Here’s the basic syntax of the chown
command:
chown [OPTIONS] OWNER[:GROUP] FILE
OWNER
: Specifies the new owner of the file or directory.GROUP
: Specifies the new group owner of the file or directory. If not specified, the group owner remains unchanged.FILE...
: Specifies the files or directories for which ownership should be changed. You can specify multiple files and directories separated by spaces.
Here are some common options used with the chown
command:
-R
or--recursive
: Recursively change the ownership of directories and their contents.-v
or--verbose
: Display a message for each file processed, showing the changes made.-c
or--changes
: Similar to-v
, but only display a message if the ownership actually changes.--from=CURRENT_OWNER[:CURRENT_GROUP]
: Specifies the current owner and/or group of the file or directory. Only files that match these criteria will have their ownership changed.--preserve-root
: Avoid operating recursively on/
.
How to Change the Owner of a File
To change the owner of a file, you can use the chown
command followed by the username or user ID of the new owner and the name of the file you want to change ownership for. Here’s the basic syntax:
chown new_owner file_name
Replace new_owner
with the username or user ID of the new owner and file_name
with the name of the file you want to change ownership for.
For example, to change the owner of a file named example.txt
to a user named john
, you would use the following command:
chown john example.txt

If you want to change both the owner and the group ownership of the file, you can use the following syntax:
chown new_owner:new_group file_name
Replace new_group
with the group name or group ID of the new group owner.
For example, to change both the owner and group ownership of the example.txt
file to a user named john
and a group named users
, you would use the following command:
chown john:users example.txt

How to Change the Owner and Group of a File
To change both the owner and group of a file, you can use the chown
command with the following syntax:
chown new_owner:new_group file_name
Replace new_owner
with the username or user ID of the new owner, new_group
with the group name or group ID of the new group owner, and file_name
with the name of the file you want to change ownership for.
For example, let’s say you want to change both the owner and group ownership of a file named example.txt
to a user named john
and a group named users
. You would use the following command:
chown john:users example.txt
This command changes both the owner and group ownership of the example.txt
file to the user john
and the group users
.
Remember, you typically need to have the necessary permissions (usually root or superuser privileges) to change the ownership of a file that you do not own.
We hope you’ve found this useful