How to Change Ownership of a Directory in Linux

How to Change Ownership of a Directory in Linux:

- This  is the format for the command:
    # chown -Rv username:group directory
(-R switch is to make it recursive that means to change the permissions for all files and directories inside of the directory)
(-v switch makes it verbose, its optional)

For Example:

- Say your using semplice linux (a debian sid based distro) in a live session and used # apt-get source foo to download and unpack the source code of a package, then you notice that you cant access the files or change the contents of that folder, because in live sessions semplice uses luckyuser as the normal user and the usergroup as well for that user, but to use apt-get source you have to be root, therefor downloading source with apt-get will make that directory under the group ownership of root, and when you check
file details you will see it listed with root:root meaning root user on root group, while any file made with luckyuser is normal user

- So lets say the source package was emacs-defaults-46.1 it was also unpacked from the package.tar.xz, but you cannot change the contents of the directory in anyway, despite even trying to change user rights on it, you have to change the group ownership

- To do that you look at the emacs-defaults_46.1.tar.xz ownership it says root:root meaning it belongs to root user as owner and group, to change it you need to make it luckyuser:luckyuser, so issue the command:

(the command format is: # chown -R username:group directory)

# chown -Rv luckyuser:luckyuser emacs-defaults-46.1

- This changes ownership to luckyuser from root, now all the settings allowed to root is allowed to luckyuser user and group
- You can now edit the directory and all of its contents or even delete it completely



0 comments:

Post a Comment