Back to course

36. Changing Ownership: The `chown` Command

Linux Basics: From Zero to CLI Hero

Reassigning the Owner

The chown command (CHange OWNer) is used to change the user who owns a file or directory. This command generally requires sudo privileges, as normal users cannot give away files they own.

Syntax

chown [options] new_owner file/directory

Changing User Ownership Only

To change the owner of website_data to a user named www-data:

bash $ sudo chown www-data website_data

Changing Both User and Group Ownership

Use a colon (:) to separate the user and the group.

To change the owner to admin and the group to devs:

bash $ sudo chown admin:devs project_files

Changing Ownership Recursively (-R)

To change the ownership of a directory and all its contents:

bash $ sudo chown -R admin:devs project_files