The chown command stands for ‘Exchange Proprietor’; it’s used to modify the landlord and staff of information, directories, and symbolic hyperlinks within the device.

To raised perceive its serve as, it’s necessary to grasp that during Linux, each and every document and listing is assigned 3 sorts of proprietor attributes:

  • Consumer: The Consumer is the person who owns the document,
  • Crew: Crew comprises different customers who’re within the document’s staff, and ,
  • Others: Customers that aren’t within the document’s staff.

Each and every of those classes could have other permission ranges for studying, writing, and executing the information.

The chown command means that you can exchange the Consumer and Crew possession of a document or listing.

chown normally calls for administrative (root) privileges to run. In case you’re no longer logged in as root, you’ll most likely wish to use sudo earlier than the command, like sudo chown consumer:staff filename, to make adjustments.

Listed here are many ways to make use of the chown command:

1. Exchange the Proprietor

The elemental syntax for converting the landlord is chown proprietor filename.

Instance :

To switch the landlord of a document named document.txt to user1, you could use:

chown user1 document.txt
2. Exchange the Proprietor and Crew

You’ll exchange the landlord and staff on the identical time by means of keeping apart the landlord and staff with a : (colon).

Instance :

To switch the landlord of document.txt to user1 and the staff to group1, you could use:

chown user1:group1 document.txt
3. Exchange the Proprietor of a Listing and Its Contents

You’ll exchange the landlord of a listing and all its contents the usage of the -R (or --recursive) choice.

Instance :

To switch the landlord of a listing named dir and all its contents to user1, you could use:

chown -R user1 dir
4. Exchange the Proprietor of All Information in a Listing

To switch the landlord of all information in a listing with out converting the landlord of the listing itself or any subdirectories, you’ll be able to use the * wildcard.

Instance:

chown user1 dir/*
5. Exchange the Crew Best

If you wish to exchange the gang with out converting the landlord, you’ll be able to achieve this by means of prefixing the gang with a : (colon).

Instance:

To switch the gang of document.txt to group1, you could use:

chown :group1 document.txt
6. Exchange the Proprietor and Crew to the Login Consumer

You’ll exchange the landlord and staff of a document or listing to the login consumer with out specifying the consumer title.

Instance:

chown $USER:$USER document.txt

The publish How you can Use chown in Linux gave the impression first on Hongkiat.

WordPress Website Development Source: https://www.hongkiat.com/blog/linux-command-chown/

[ continue ]