To change the ownership of a directory in Linux, you can use the chown command. Here’s how to do it:
Open the terminal.
Use the
chowncommand with the desired owner and group. The syntax is:sudo chown owner:group /path/to/directoryowneris the new owner's username.groupis the new group name (optional)./path/to/directoryis the path to the directory whose ownership you want to change.
Example: To change the ownership of a directory named
mydirto useraliceand groupdevelopers, you would run:sudo chown alice:developers mydirTo change ownership recursively: If you want to change the ownership of the directory and all its contents (files and subdirectories), add the
-Roption:sudo chown -R owner:group /path/to/directoryFor example:
sudo chown -R alice:developers mydirVerify the change: You can check the ownership of the directory using:
ls -ld /path/to/directory
This will display the current owner and group of the directory.
