How to change ownership of subdirectories?

QuestionsQuestions8 SkillsProPermissions of FilesNov, 17 2025
0117

To change the ownership of subdirectories along with their contents, you can use the chown command with the -R (recursive) option. This will apply the ownership change to the specified directory and all its subdirectories and files.

Syntax

sudo chown -R new_user:new_group /path/to/directory

Example

To change the ownership of a directory named data_directory and all its subdirectories and files to the user new_user and group new_group, you would use:

sudo chown -R new_user:new_group data_directory

Key Points

  • -R: This option stands for recursive, meaning it will change the ownership for all files and subdirectories within the specified directory.
  • new_user:new_group: You can specify both a new owner and a new group. If you only want to change the owner, you can omit the group (e.g., new_user:).

Using the -R option should be done with caution, especially in system directories, as it can affect system functionality if used incorrectly.

0 Comments

no data
Be the first to share your comment!