chown Linux Command
Changes the owner and/or group of a file or directory.
What does chown do?
Changes the owner and/or group of a file or directory.
Syntax
chown [options] owner[:group] filePractical example
sudo chown kali:users file.txtQuestions about chown
How do I change the owner of a file?
Use `sudo chown newowner filename` to change only the owner. You need root privileges to change file ownership.
How do I change both owner and group?
Use `sudo chown newowner:newgroup filename` to change both the owner and group in a single command.
How do I change ownership recursively?
Use `sudo chown -R newowner:newgroup directory/` to recursively change ownership of a directory and all its contents.
How do I change only the group?
Use `sudo chown :newgroup filename` (with a colon before the group name) or `sudo chgrp newgroup filename` to change only the group.
Why do I need sudo for chown?
Only root can change file ownership. This is a security measure to prevent users from giving away files to other users.
How do I find the current owner of a file?
Use `ls -l filename` to see the owner and group in the third and fourth columns of the output.
How do I change ownership of all files in a directory?
Use `sudo chown -R user:group /path/` to change everything. For just the directory itself without recursion, omit the `-R` flag.
Related Permission Commands
chmodChanges the read, write, and execute permissions of files and directories.
chgrpChanges the group ownership of a file or directory.
visudoSafely edits the /etc/sudoers file to configure sudo permissions.
umaskSets the default permission mask for newly created files and directories.
sudo -lLists the allowed and forbidden sudo commands for the current user.
getfaclDisplays the Access Control List (ACL) of a file or directory.