The chown command in Linux is used to change the ownership of files and directories. It allows you to change the user and group ownership, granting specific users or groups control over file permissions.
Basic Syntax
chown [OPTIONS] USER[:GROUP] FILE
USER: The new owner of the file.
GROUP: The new group (optional).
FILE: The file or directory to change ownership.
Examples
- Change user ownership:
chown newuser file.txt
- Change user and group ownership:
chown newuser:newgroup file.txt
- Change ownership recursively for directories:
chown -R newuser:newgroup /path/to/directory
Common Options:
-R: Recursively change ownership for all files and subdirectories.
–reference=RFILE: Use the ownership of RFILE as a reference.
Permissions: Only the root user or users with appropriate permissions can change file ownership. Misuse can affect system stability and security, so use with caution. Always verify changes using ls -l to confi