The chown command in Linux is used to change the ownership of a file or directory. It allows you to modify both the user and group ownership of a file.
Syntax
The basic syntax of the chown command is:
chown [OPTION]... [OWNER][:[GROUP]] FILE...
Key Components
- OWNER: The new owner of the file.
- GROUP: The new group associated with the file (optional).
- FILE: The file or directory whose ownership you want to change.
Example Usage
-
To change the owner of a file named
example.txttouser1, you would use:sudo chown user1 example.txt -
To change both the owner to
user1and the group togroup1, you would use:sudo chown user1:group1 example.txt
Important Note
- The
chowncommand typically requires superuser (root) privileges, so you may need to usesudobefore the command to execute it successfully.
