Robert Elder Software Inc.
  • Home
  • Store
  • Blog
  • Contact
  • Home
  • Store
  • Blog
  • Contact
  • #linux
  • |
  • #commandline
  • |
  • #softwareengineering
  • |
  • #embeddedsystems
  • |
  • #compilers
  • ...
  • View All >>

Intro To 'chown' Command In Linux

2023-05-04 - By Robert Elder

     I use the 'chown' command to change the user and group ownership of files and directories.  Here, I have a file that's currently owned by the user 'robert':

ls -l file1.txt
-rw-rw-r-- 1 robert robert 0 May  4 23:54 file1.txt

     This command will change the user ownership of file1.txt from 'robert' to 'mike':

chown mike file1.txt

     And now, you can see that 'file1.txt' is owned by 'mike':

ls -l file1.txt
-rw-rw-r-- 1 mike robert 0 May  4 23:54 file1.txt

     The 'chown' command can also perform the functions of the 'chgrp' command as well.  If we start with 'file1.txt' again with the owner and group set to 'robert':

ls -l file1.txt
-rw-rw-r-- 1 robert robert 0 May  4 23:54 file1.txt

     This command will change both the user and group ownership at the same time from 'robert' to 'mike':

chown mike:mike file1.txt

     And here, you can verify that both the user and group have been set to 'mike':

ls -l file1.txt
-rw-rw-r-- 1 mike mike 0 May  4 23:54 file1.txt

     The file permissions associated with the user and group are located here:

Linux Group Permissions

Using 'chown' To Recursively Change Ownership

     Here, I have a directory with a bunch of files that are all owned by the user and group 'robert':

ls -l docs
total 4
-rw-rw-r-- 1 robert robert    0 May  5 00:13 cat.jpg
-rw-rw-r-- 1 robert robert    0 May  5 00:13 dog.jpg
drwxrwxr-x 2 robert robert 4096 May  5 00:13 more-docs
-rw-rw-r-- 1 robert robert    0 May  5 00:13 README.txt

     You can use the '-R' flag with the 'chown' command to recursively change the ownership of all items in a directory:

chown -R mike:mike docs

     And now, you can see that all files in this directory are owned by the user and group 'mike':

ls -l docs
total 4
-rw-rw-r-- 1 mike mike    0 May  5 00:13 cat.jpg
-rw-rw-r-- 1 mike mike    0 May  5 00:13 dog.jpg
drwxrwxr-x 2 mike mike 4096 May  5 00:13 more-docs
-rw-rw-r-- 1 mike mike    0 May  5 00:13 README.txt

     And that's why the 'chown' command is my favourite Linux command.

Intro To 'stty' Command In Linux
Intro To 'stty' Command In Linux
Published 2023-10-04
Terminal Block Mining Simulation Game
$1.00 CAD
Terminal Block Mining Simulation Game
Intro To 'nproc' Command In Linux
Intro To 'nproc' Command In Linux
Published 2023-07-15
Intro To 'comm' Command In Linux
Intro To 'comm' Command In Linux
Published 2023-09-06
How To Force The 'true' Command To Return 'false'
How To Force The 'true' Command To Return 'false'
Published 2023-07-09
A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01
Intro To 'chroot' Command In Linux
Intro To 'chroot' Command In Linux
Published 2023-06-23
Join My Mailing List
Privacy Policy
Why Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it.  Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked!  You'll get some emails with examples of things that I sell.  You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right?  Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
© 2025 Robert Elder Software Inc.
SocialSocialSocialSocialSocialSocialSocial
Privacy Policy      Store Policies      Terms of Use