chown Linux Command Guide
The chown
command in Linux is used to change the ownership of files and directories. It allows users to transfer ownership of a file or directory to a specific user or group. This command is essential for system administrators to manage file permissions and access control. By understanding the syntax and options of the chown
command, users can effectively control who can access and modify files on a Linux system.
chown Syntax:
Options:
Option | Description |
---|---|
-c | Report only when a change is made |
-f | Suppress most error messages |
-h | Change the group of a symlink |
-R | Recursively change files and directories |
-v | Output a diagnostic for every file processed |
Parameters:
Parameter | Description |
---|---|
user | The user ownership to be set |
group | The group ownership to be set |
file | The file or directory to change ownership of |
chown Command Samples:
Change Ownership of a File
Changes the ownership of the file.txt to user1.
Change Ownership of a Directory Recursively
Changes the ownership and group ownership of the directory and all its contents recursively to user2 and group2.
Change Ownership of Multiple Files
Changes the ownership and group ownership of file1.txt and file2.txt to user3 and group3.
Change Only the Group Ownership of a File
Changes only the group ownership of file3.txt to group4.
Change User and Group Ownership of a Symbolic Link
Changes the user and group ownership of the symbolic_link.
Preserve the Original Owner on Copy
Preserves the ownership of origin.txt and applies it to destination.txt.
Change Ownership for All Files in a Directory
Changes the ownership of all files in the current directory to newuser and newgroup, displaying a message for each file changed.
chown FAQ:
How do I change the owner of a file in Linux?
To change the owner of a file in Linux, use the following command:
How do I change the group of a file in Linux?
To change the group of a file in Linux, use the following command:
How do I change both the owner and group of a file in Linux?
To change both the owner and group of a file in Linux, use the following command:
How do I change the owner of a directory and its contents in Linux recursively?
To change the owner of a directory and its contents in Linux recursively, use the following command:
How do I change the owner of a file using the numeric UID in Linux?
To change the owner of a file using the numeric UID in Linux, use the following command:
How do I change the group of a file using the numeric GID in Linux?
To change the group of a file using the numeric GID in Linux, use the following command:
Applications of the chown command
- Change the owner of a file
- Change the group owner of a file
- Recursively change ownership of files and directories
- Change ownership of a symbolic link
- Change ownership of multiple files at once