banner



How To Set Ownership For Files Directories

All files and directories that exist on your Linux system have an owner, a group, and permission access rights that are granted to the file owners, its grouping members, or others. The chown command permits a Linux user to change whatsoever directory or file's buying. In this post, nosotros will demonstrate the usage of the chown command for changing buying through practical examples. But firstly, you should empathise why you would want to change the ownership of any directory or file?

Here is the list of few scenarios in which you want to do this:

  • For example, yous want an already created directory or file to exist accessible to a particular user.
  • When a user leaves an organisation, all of his data comes nether the responsibility of another employee. Therefore, yous want to change the ownership of the new squad fellow member.
  • Changing directory or file ownership is too necessary when you are writing a script that has to be used past only a specific person.
  • Transferring files between different Linux systems as well requires changes in files and directories ownership.

Now let'southward cheque out the syntax of the chown command.

chown command syntax

chown [Options] User[:Grouping] File(s)

Utilize the "User" for the username or replace it using the user ID, also known equally UID. Add the group proper noun in the "Grouping" function of the GID (group ID). At the end of the chown command, add files or directories for which you want to modify the buying.

Changing the owner of a directory

Nosotros have created a split up user named "utest" and a group "ugroup" for demonstrating the examples. To change the ownership of whatever directory, utilize the chown command with the username and path of the directory.

$ sudo chown utest ./samplefolder/

Now, write out the "ls" command and check if your directory buying is updated or not.

$ ls -fifty -d ./samplefolder/

Changing the ownership of all sub-directories

Utilise the "-R" option of the chown command for changing the owners of all the files or folders nowadays in a directory.

$ sudo chown -R utest ./samplefolder/

List out the directory content to view the results.

Changing the owner of a file

First of all, listing out the file content to know about its ownership.

Afterwards that, specify the proper noun of the user who you want to be the new owner of this file. In our instance, nosotros have chosen "utest" to avail the buying of "samplefile.txt."

$ sudo chown utest samplefile.txt

Again, verify the updated ownership changes.

You can also employ the "User ID" or "UID" of whatever user for this purpose. For that, think the user ID of the new user by utilizing the "id" command with the "-u" option.

Add the User ID instead of the username to brand the ownership changes.

$ sudo chown 1001 samplefile.txt

Changing the owners of multiple files

Specify the file names at the terminate of the chown command to change the ownership of multiple files at once.

$ sudo chown utest samplefile.txt samplefile2.txt

Write out the below-given command to ostend the changes.

$ sudo ls -al samplefile.txt samplefile2.txt

Changing the owner of directory and file at one time

Follow the beneath-given method for changing the owners of the file and directory instantly.

$ sudo chown utest samplefile.txt test

This command will make "utest" the new owner of the "exam directory" and the "samplefile.txt."

Changing the possessor using wildcards

Wildcards are used to select a specific file group according to the given design. The chown command volition so change the owner of the files subsequently retrieving them from the wildcard execution.

$ sudo chown utest s*.*
$ sudo ls -l  due south*.*

Decision

For information security concerns, y'all may want to specify the buying of files and directories. In Linux, nosotros utilize the chown command-line utility for changing the ownership of directories or files. You tin also employ this command for changing directories and multiple file ownership at once. In this post, all of these statements are justified past providing practical examples.

About the author

Talha is a correspondent at Linux Hint with a vision to bring value and do useful things for the world. He loves to read, write and speak about Linux, Data, Computers and Technology.

How To Set Ownership For Files Directories,

Source: https://linuxhint.com/change-directory-owner-linux/

Posted by: fisherperess42.blogspot.com

0 Response to "How To Set Ownership For Files Directories"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel