To change file ownership 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 filenameowneris the new owner's username.groupis the new group name (optional).filenameis the name of the file whose ownership you want to change.
-
Example: To change the ownership of a file named
example.txtto userjohnand groupstaff, you would run:sudo chown john:staff example.txt -
Verify the change: You can check the ownership of the file using:
ls -l example.txt
This will display the current owner and group of the file. If you want to change ownership recursively for a directory and all its contents, add the -R option:
sudo chown -R owner:group /path/to/directory
