How to Change File Ownership Using chown

How to Change File Ownership Using chown in Linux

Welcome to this Linux tutorial! 👋

Today we’re going to learn a powerful command used for managing files and permissions — the chown command.

So, what does chown do?

chown stands for “change ownership.” It allows us to change who owns a file or directory on a Linux system.

Let’s start with a simple real-life example...


👨‍💻 Example Scenario

Imagine you’re an admin and you’ve just created a file, but now you want to assign it to another user named john. Here’s how you do it.

sudo chown john file.txt

This command changes the owner of file.txt to the user john.

Let’s walk through it step by step.


🔍 Step 1: Check Current Ownership

We’ll use the ls -l command to check who owns the file.

ls -l file.txt
-rw-r--r-- 1 root root 0 Jul 2 11:00 file.txt

Here, the file is owned by root (user and group).


🔧 Step 2: Change Ownership to Another User

sudo chown john file.txt

This changes the user owner to john, but keeps the group as it is.

Verify again:

ls -l file.txt
-rw-r--r-- 1 john root 0 Jul 2 11:00 file.txt

👥 Step 3: Change Both User and Group Ownership

Let’s say you also want to change the group to john’s group:

sudo chown john:john file.txt

That’s user:group format.

-rw-r--r-- 1 john john 0 Jul 2 11:00 file.txt

Perfect! 🎯


📁 Bonus: Change Ownership Recursively

What if you want to change ownership for a folder and everything inside it?

sudo chown -R john:john my_folder/

The -R flag makes the operation recursive, changing ownership for all subfolders and files too.


🧠 Summary

  • chown user file — change file owner
  • chown user:group file — change owner and group
  • chown -R user:group folder/ — recursive change

That’s it! 🎉 You now know how to change file ownership using chown in Linux.

Practice it, and you’ll get comfortable managing permissions like a pro!


Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...