Linux chown Command Change Owner

The Linux chown command is used to change the owner and group of a file or directory. If you have a directory and you are not the owner and would like to be the owner of that directory, you can use the Linux chown command to change the owner to your username.

Some of you may get a lot of permission denied errors while trying to open files or folders, this may be caused by improper ownership or owner permissions. If it is a ownership problem, chown will fix your problem. If it is a permission problem, then you will want to look into chmod.

The usage of chown is chown [OPTIONS] [OWNER]:[GROUP] [FILE]. There are many options for chown, but I only use 2 of them on a regular basis. I use chown -R | --recursive and also chown --from=CURRENT_OWNER:CURRENT_GROUP. Basically chown -R is used on directories and all files in that directory. chown --from=CURRENT_OWNER:CURRENT_GROUP is used if you want to only change files that are currently owned by CURRENT_OWNER:CURRENT_GROUP.

For some examples of the Linux chown command. Say I have a desktop computer with Linux on it, and my username on the desktop computer is BrandonStimmel, and I buy a new laptop and install Linux on it, and this time I made my username Brandon. I also want to get rid of my desktop because it is slow and uses a lot of electricity. So I want to copy all of my files and folders from the desktop’s /home/BrandonStimmel to the laptop’s /home/Brandon. I simply use rsync, cp, or scp to copy the files and folders from the desktop computer to the laptop computer. Trouble is, I can only read files, I can’t write to them. I keep getting permission denied errors, and you don’t have permission to write to the file $FILE. So I login to the laptop as my user, then su to root, since root has permissions to read and write to the files/folders. Then I run chown -R --from=BrandonStimmel:users Brandon:users /home/Brandon/* Some may ask why I used chown --from= in this example. Well I have a ton of files in my home folder from my desktop and I may have some files that were meant to be owned by root, or some other user as backups. I didn’t want to change all of them to my new username unless I owned them before.

If you use the same example but don’t care who previously owned the files/folders, you can run chown -R Brandon:users /home/Brandon/* and you will change all files/folders in /home/Brandon to be owned by the username Brandon and the group users.

I hope this Linux tutorial on the Linux chown command has helped you fix your permission issues. If you have any questions please feel free to contact Beginner Linux Tutorial by leaving a comment or sending an email. Have a great day and remember to read more Linux tutorials! Knowledge is power, especially with Linux!

Comment Linux tutorial or Leave a Trackback

One Comment

  1. RajeshKumar.D
    Posted November 17, 2011 at 9:48 am | Linux tutorial comment

    Thank you very much, very clear explanation. Thanks…

2 Trackbacks

  1. […] chown – Linux command to change ownership of a file|directory. […]

  2. By Linux chmod Command | Beginner Linux Tutorial on December 25, 2011 at 10:38 pm

    […] directory you would first make sure that family-photos is owned by the family group, by using the chown command. Then add permissions using the chmod […]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*