Skip to main content

Unit 2 · Basic Commands · Lesson 20 of 34

chown

chown

Similar to chmod, chown (change owner) is used to change the user or group affiliated with a file. To see a file's current owner and group, use ls -l, just like in the chmod lesson.

chown has a few different formats depending on what you want to change:

  • chown user file.txt → changes the owner only
  • chown user:group file.txt → changes both the owner and the group
  • chown user: file.txt → changes the owner, and sets the group to that user's primary group
  • chown :group file.txt → keeps the current owner, changes only the group

Just remember that whatever you specify gets changed, whatever you leave out stays the same!

⚠️ One catch: handing a file to a different user is something only root can do, so on your box you can't give your files away. Changing the group on a file you already own is fair game, though, and that's what the tasks below are about.


Try it

There's a folder called lab in your home directory with two files in it that came back from a backup with the wrong group stamped on them. Take a look first:

cd lab
ls -l

You'll see roster.txt sitting in the staff group and mission.txt in games, even though you own both. Your group is user, so put them back.

Live Linux terminal

This lesson comes with a real Ubuntu machine that runs in your browser, so you type every command yourself. Create a free account to do this part.

Do this lesson for real

With a free account you get the terminal, the challenges and the checks that go with every lesson in Intro to Linux, and your progress is saved as you go. CyberAcad is a 501(c)(3) nonprofit, so there is nothing to pay.