Skip to content

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:

Terminal window
chown [options] [user][:group] file

Options:

OptionDescription
-cReport only when a change is made
-fSuppress most error messages
-hChange the group of a symlink
-RRecursively change files and directories
-vOutput a diagnostic for every file processed

Parameters:

ParameterDescription
userThe user ownership to be set
groupThe group ownership to be set
fileThe file or directory to change ownership of

chown Command Samples:

Change Ownership of a File

Terminal window
chown user1 file.txt

Changes the ownership of the file.txt to user1.

Change Ownership of a Directory Recursively

Terminal window
chown -R user2:group2 directory/

Changes the ownership and group ownership of the directory and all its contents recursively to user2 and group2.

Change Ownership of Multiple Files

Terminal window
chown user3:group3 file1.txt file2.txt

Changes the ownership and group ownership of file1.txt and file2.txt to user3 and group3.

Change Only the Group Ownership of a File

Terminal window
chown :group4 file3.txt

Changes only the group ownership of file3.txt to group4.

Terminal window
chown user5:group5 symbolic_link

Changes the user and group ownership of the symbolic_link.

Preserve the Original Owner on Copy

Terminal window
cp -p origin.txt destination.txt
chown --reference=origin.txt destination.txt

Preserves the ownership of origin.txt and applies it to destination.txt.

Change Ownership for All Files in a Directory

Terminal window
chown -c newuser:newgroup *

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:

Terminal window
chown newowner myfile.txt

How do I change the group of a file in Linux?

To change the group of a file in Linux, use the following command:

Terminal window
chown :newgroup myfile.txt

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:

Terminal window
chown newowner:newgroup myfile.txt

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:

Terminal window
chown -R newowner mydirectory

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:

Terminal window
chown 1000 myfile.txt

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:

Terminal window
chown :1000 myfile.txt

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