Linux Chown Command Tutorial with Examples To Change Ownership Of Files

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-chown-command-tutorial-examples-change-ownership-files/
PINTEREST
PINTEREST
INSTAGRAM

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

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.

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 .

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 .

LEARN MORE  Linux Chmod Command Tutorial with Examples To Change Permission of Files and Folders

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 .

$ 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.

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.

Verbose Mode
Verbose Mode
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-chown-command-tutorial-examples-change-ownership-files/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.