Changing File Ownership with `chown`
The `chown` command is used to change the owner and/or group of a file or directory. This command is typically only available to the root user.
Basic `chown` Usage
Change file owner
sudo chown [new_owner] [file]Changes the owner of the specified file to `new_owner`.
Change file group
sudo chown :[new_group] [file]Changes the group of the specified file to `new_group`. Note the colon `:` before the group name.
Change owner and group simultaneously
sudo chown [new_owner]:[new_group] [file]Changes both the owner and the group of a file in one command.
Recursive Ownership Change
Change ownership of a directory and its contents
sudo chown -R [new_owner]:[new_group] [directory]The `-R` flag (recursive) changes the owner and group of the directory and all files and subdirectories within it.