chown
Change file owner and group
TLDR
Change the owner user of a file/directory
Change the owner user and group of a file/directory
Change the owner user and group to both have the name user
Recursively change the owner of a directory and its contents
Change the owner of a symbolic link
Change the owner of a file/directory to match a reference file
SYNOPSIS
chown [OPTION]... [OWNER][:[GROUP]] FILE...
PARAMETERS
-c, --changes
Report only when a change is made.
-f, --silent, --quiet
Suppress most error messages.
-v, --verbose
Output a diagnostic for every file processed.
-R, --recursive
Operate on files and directories recursively.
--from=CURRENT_OWNER:CURRENT_GROUP
Change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omitted, in which case a wildcard value is assumed.
--dereference
affect the referent of each symbolic link, rather than the symbolic link itself
--no-dereference
affect symbolic links instead of any referenced file (this is the default)
--preserve-root
fail to operate recursively on '/'
--reference=RFILE
use RFILE's owner and group rather than specifying OWNER:GROUP values
--help
display this help and exit
--version
output version information and exit
DESCRIPTION
The chown command in Linux changes the user and/or group ownership of files or directories. It's a fundamental command for managing file permissions and access control. Using chown, you can specify a new owner, a new group, or both for one or more files or directories. Proper use of chown ensures that only authorized users or groups can access and modify critical system files or user data. Incorrect use can lead to security vulnerabilities. The command typically requires root privileges or ownership of the file in question to change the ownership. The command recursively changes ownerships if the -R option is provided. The chown command relies on User ID and Group ID to perform its job.
CAVEATS
Using chown incorrectly can severely impact system security by granting unauthorized access to files. Always exercise caution and double-check your commands, especially when using the recursive option (-R).
EXAMPLES
- Change the owner of a file:
chown user file.txt
- Change the owner and group of a file:
chown user:group file.txt
- Recursively change the owner of a directory:
chown -R user directory
HISTORY
The chown command is a standard utility present in Unix-like operating systems since their early days. Its primary function has always been to change the ownership of files, reflecting the fundamental need for access control in multi-user systems.