How to use chown command in linux |wiz maverick

Опубликовано: 08 Октябрь 2024
на канале: wiz maverick
513
2

The concept of owner and groups for files is fundamental to Linux. Every file is associated with an owner and a group. You can use chown and chgrp commands to change the owner or the group of a particular file or directory.

In this article, we will discuss the ‘chown’ command as it covers most part of the ‘chgrp’ command also.

Even if you already know this command, probably one of the examples mentioned below might be new to you.

1) How to change the owner of a file?
chown [new-owner] [file-name]
chown mhassan test222.txt

2) How to change the group of a file?
chown :[group-name] [file-name]
chown :hassan test222.txt

3) How to change group ownership to login group of the specified user?
chown mhassan: test222.txt

4)How to change both the owner and group of a file?
chown [new-owner]:[new-group] [file-name]

chown mhassan:operations test222.txt
chown -R mhassan:operations tt

5) How to change the owner or group (or both) after checking existing owner/group?
chown --from=[curr-own]:[curr-group] [new-owner]:[new-group] [filename]
chown --from=mhassan:root root:root test222.txt

6) How to pick owner/group information from a reference file?
chown --reference=[ref-file-name] [filename]
chown --reference=test222.txt 2019-08-27\ 12-33-10.flv


#linux
#chown
#centos
#howtochowncommand