shellinfo tips

Using chown in Linux

Understanding file permissions and ownership is a crucial aspect of maintaining a secure Linux environment. The chown command, which stands for ‘change owner’, is one of the key commands that can help you manage these effectively. In this blog post, we’ll dive deep into the usage of chown and illustrate it with practical examples.
What is chown?

The chown command in Linux is used to change the owner and group ownership of files and directories. It is an essential command for system administrators for managing permissions and access to files and directories.
Syntax of chown

The basic syntax of the chown command is:

chown [OPTION]... [OWNER][:[GROUP]] FILE...

Here, OWNER and GROUP represent the user and group names (or IDs) that you want to assign to the specified FILE or directory. The OPTION part represents optional flags that you can include to modify the behavior of the command.
Examples of Using chown

Now, let’s explore some practical examples of using chown.

Basic Usage of chown

To change the owner of a file, use chown followed by the new owner’s username and the filename. For example, to change the owner of a file named myfile.txt to a user named john, you would use:

chown john myfile.txt

Changing the Owner and Group

You can change both the owner and group of a file or directory by separating the new owner and group with a colon (:). For example, to change the owner of myfile.txt to john and the group to admin, you would use:

chown john:admin myfile.txt

Changing Ownership Recursively

If you want to change the ownership of a directory and all of its contents, you can use the -R (or –recursive) option. For example, to change the owner of a directory named mydir and all of its contents to john, you would use:

chown -R john mydir

Changing Ownership of Multiple Files

You can also change the ownership of multiple files at once. Just list all the filenames, separated by spaces. For example, to change the owner of file1.txt, file2.txt, and file3.txt to john, you would use:

chown john file1.txt file2.txt file3.txt


The chown command is a powerful tool in Linux for managing file and directory ownership. While it’s most commonly used by system administrators, understanding chown can also be useful for regular users who want to manage their files more effectively. Remember, as with any command that can change system settings, be careful when using chown and make sure you understand the changes you’re making. Practice these examples and explore the man pages (man chown) to learn more about the other options available with chown.