Change Owner and Group of a File in Linux

[ad_1]

Change group and owner of file in linux ubuntu; Just simply type the chown [Options][Owner][:[Group]] fileName or FolderName command in Command line and press enter. Also, type the folder name instead of file name on command to change owner and group of directory.

The linux chown command helps us to change a file or folder ownership and group on command line linux ubuntu. And chown provides flexibility in managing file and directory permissions.

Here’s a breakdown of its basic syntax:

chown [OPTIONS] USER[:GROUP] FILE
  • [OPTIONS]: Optional flags that modify the action of the chown command.
  • USER: The new owner’s username to be assigned to the file or directory.
  • :GROUP: An optional parameter specifying the new group for the file or directory.
  • FILE: The name of the file or directory whose ownership and Group are being changed.

Here are some approaches to changing the owner and group of files or folders in Linux:

Approach 1: How to Change the Owner of a File in Linux

To change the ownership of a file in Linux, type the command chown USERNAME FILENAME at the Linux command line and press Enter; You can use this on command line like this:

chown USERNAME FILENAME

Let’s say you have a file named FileName1 and an owner named TutsmakeUser, type the command chown TutsmakeUser fileName1 at the command line to change the owner of the file named FileName1 to the new ownership named TutsmakeUser; You can see this:

chown TutsmakeUser fileName1

Approach 2: How to Change the Group of a File in Linux

To change ownership of a file to a group, so that all members of the group can access the file, type the chown :GROUPNAME FILENAME command at the Linux command prompt and press Enter, You can use this on command line like this:

chown :GROUPNAME FILENAME

Let us assume that you have a group named var-www-html and along file named testFile.txt, To change the owner of the testfile.txt file to the var-www-html group, type the command chown :var-www-html testFile.txt at the linux command prompt, so that all members of the var-www-html group can access testFile.txt; You can see this:

chown :var-www-html testFile.txt

Approach 3: How to Change the Owner and Group of a File in Linux

To change the ownership and Group of a file in Linux, type the command chown USERNAME:GROUPNAME FILENAME at the Linux command line and press Enter; You can use this on the command line like this:

chown USERNAME:GROUPNAME FILENAME

Let’s say you have a file named testFile.pdf, an owner named tutsUser, and group named tutsmakeGroup, type the command chown tutUser:tutsmakeGroup testFile.pdf at the Linux command line to change the owner and group of the specific file named testFile.pdf to the new ownership named tutsUser and a new group named tutsmakeGroup; You can see this:

chown tutUser:tutsmakeGroup testFile.pdf

Approach 4: How to Change the Owner of Files in Directory Linux

To change the ownership of all files in a directory, you need to use the chown USERNAME DIRECTORYNAME command with the -R option on the Linux command line.

Just type chown -R USERNAME DIRECTORYNAME command on the command line and press enter, it will recursively change the ownership of all files in the directory;

chown -R USERNAME DIRECTORYNAME

For example, to change the owner of all files in the currrent directory var/www/html, Type chown -R USERNAME DIRECTORY_NAME command on command line and press enter for that:

chown -R USERNAME DIRECTORY_NAME

Approach 5: How to Change Group and Owner of Files in a Directory Linux Recursively

To change the ownership and group of all files in a directory, you need to use the chown -R USERNAME:GROUPNAME DIRECTORYNAME command with the -R option on the Linux command line.

Simply type the command chown -R USERNAME:GROUPNAME DIRECTORYNAME on the Linux command line and press Enter, this will recursively change the ownership as well as the group of all files in the directory;

chown -R USERNAME:GROUPNAME DIRECTORYNAME

For example, to change the ownership and group of all files in a directory to the user jolly, the group LLB, and the directory myFolder, you can use the command, You can use this on the command line like this:

chown -R jolly:LLB myFolder

Here is the video guide on how to change ownership and group of files or folders in linux:

Conclusion

That’s it; you have learned how to change the ownership and group of files or folders in Linux using chown command.

Recommended Tutorials

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
Jassweb, Rai Chak, Punjab, India. 143518