Skip to main content

Module 6: User & Permission Management

Lesson 53: chown Command

In this lesson, you'll learn how to use the chown command to change the ownership of files and directories in Linux.

As we know in Linux, everything is a file, which means all input/output resources, such as files, directories, disk drives, printers, etc., are exposed as files through the filesystem namespace.

In addition to this, there is ownership associated with each and every file in Linux, which is represented by two entities - user and group.

The combination of access permissions and ownership allows Linux to implement an access control mechanism in an effective way.

Let's discuss a useful command named chown which is utilized to change the ownership of files.

chown Command Syntax

The syntax of the chown command is as follows:

$ chown [OPTION]... [OWNER][:[GROUP]] [FILE-1] [FILE-2]...[FILE-N]

chown Command Options

Option Description
-h Change ownership of the symbolic link itself, not the referenced file
--from USER:GROUP Change ownership only if the current owner matches the specified user and group
--reference=FILE Copy ownership from a reference file
-R Change ownership of files and directories recursively
-v Enable verbose mode and print diagnostics for each processed file
-f Suppress error messages

Now, let's understand the usage of the chown command with some practical examples in Linux.

1. Find the Ownership of a File

The easiest way to find the owner of the file is using the ls command, which will list the user and group of the file.

$ touch file-1.txt
$ ls -l file-1.txt
-rw-r--r-- 1 ubuntu ubuntu 0 Nov  5 11:42 file-1.txt

In the above output, we can see that the file is owned by the "Ubuntu" user and group. This information is represented by the third and fourth columns, respectively.

2. Change the Ownership of a File

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’