Linux Chown Command Tutorial


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

chown Command Syntax

Syntax of chown is like below.

chown OPTIONS USER:GROUP FILE

List User and Group Owner Of The Files and Folders

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 users and a group of the current working path.

$ ls -l
List User and Group Owner Of The Files and Folders

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 Of The File and Folder

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

$ chown ismail acknow.txt

Change Owner Group Name Of The File and Folder

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

$ chown :ismail acknow.txt

Change  User and Owner Group Name

In previous steps, we have changed the user and group ownership 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 .

$ chown ahmet:ismail acknow.txt

Change Files and Folders Ownership Recursively

Changing the ownership of files one by one is not a practical 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

chown Command Verbose Mode

While changing files 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

LEARN MORE  Linux Chroot Command Tutorial with Examples

Leave a Comment