Linux Chown Command Tutorial with Examples To Change Ownership Of Files

chown command is used to change file and folders user , group and other ownership. chown is very useful tool but sometimes becomes very dangerous because it can harm current owner policy.chown mainly changes read , write and execute owner according to given user or group.


Syntax of chown is like below.


List User and Group Owner

Before starting to change file and folders owner in Linux we should list current owners of the file. We will use ls -l command which will list all files owner user and group of current working path.

$ ls -l

In this example we can see that all files have owner user ismail and owner group ismail .

Using Root Account

While changing permissions and ownership in Linux the most straightforward way is using root account. Root account provides highest privileges so we will have the power to change things.

Change  Owner User Name

The simplex usage form of chown is changing owner user of given file. We will simple specify the owner username of file and file name to do this. In this example we will change owner user of file named acknow.txt to ismail .

$ chown ismail acknow.txt

Change  Owner Group Name

As we know the files and folders in linux have owner users and owner groups . We can also change owner group with chmod command. We will put the new group name after : . In this example we will change owner group to ismail .

$ chown :ismail acknow.txt

Change  User and Owner Group Name

In previous steps we have changed the user and group ownerships of files in separate steps. We can do this user and group ownership change in a single step with : . In this example we will change user ownership to ahmet and group ownership ismail .

LEARN MORE  User Groups in Linux

$ chown ahmet:ismail acknow.txt

Change Recursively and Folder Ownership

Changing ownership of files one by one is not a practical an easy solution if we have 1000 files. Or we may need to change all ownership of folders and subfolders with their file contents. We can use -R for recursive operations.

$ chown -R ismail:ismail backup

Verbose Mode

While changing file and folders we may need to print verbose output about changes. We can use -v option in order to change this.

$ chown -v -R ismail:ismail *
Verbose Mode
Verbose Mode

Leave a Comment