What is chown (change owner)? Command to change owner of files and directories in UNIX/Linux

Explanation of IT Terms

What is chown (change owner)?

The `chown` command, short for “change owner,” is a command used in UNIX and Linux operating systems to change the ownership of files and directories. The ownership of a file or directory determines which user and group have control over it. By default, the owner is set to the user who created the file or directory, while the group ownership is usually inherited from the parent directory.

Why change ownership?

Changing the ownership of files and directories is a common task in multi-user systems or when managing file permissions. There are several scenarios where changing ownership becomes necessary:

1. **Administrative tasks**: System administrators often need to change ownership to perform maintenance, manage access permissions, or troubleshoot issues.

2. **User management**: When a user account is deleted or transferred, it’s crucial to update the ownership of the files and directories associated with that account.

3. **Security**: By changing ownership, it is possible to restrict access to sensitive files and directories by giving ownership only to authorized users or groups.

How to use the chown command?

The syntax for the `chown` command is as follows:

“`bash
chown [OPTION]… [OWNER][:[GROUP]] FILE…
“`

– `[OPTION]`: Refers to any additional options to modify the behavior of the command.
– `[OWNER]`: Represents the new user who will become the owner of the file.
– `[GROUP]`: (optional) Denotes the new group that will become the file’s group owner.
– `FILE…`: Specifies the file or files for which the ownership needs to be changed. Multiple files can be specified with space separation.

Examples:

1. To change the owner of a single file named `myfile.txt` to a user called `newuser`, use the following command:

“`bash
chown newuser myfile.txt
“`

2. To change the owner of a directory named `mydir` and all its contents recursively to `newuser`, use the following command:

“`bash
chown -R newuser mydir
“`

3. To change both the owner and group, separate the owner and group names with a colon (`:`):

“`bash
chown newuser:newgroup myfile.txt
“`

It’s important to note that the `chown` command requires appropriate permissions. Only the root user or the current owner of the file (with sufficient privileges) can change the ownership.

Summary

The `chown` command plays a crucial role in UNIX and Linux systems, allowing users to change the ownership of files and directories. By modifying the ownership, users can control access, ensure security, and manage administrative tasks effectively. Understanding and correctly utilizing the `chown` command is essential for system administrators and users alike in order to maintain proper file management.

Reference Articles

Reference Articles

Read also

[Google Chrome] The definitive solution for right-click translations that no longer come up.