How to change directory ownership?

QuestionsQuestions4 SkillsProPermissions of FilesAug, 25 2025
0169

To change the ownership of a directory in Linux, you can use the chown command. Here’s how to do it:

  1. Open the terminal.

  2. Use the chown command with the desired owner and group. The syntax is:

    sudo chown owner:group /path/to/directory
    
    • owner is the new owner's username.
    • group is the new group name (optional).
    • /path/to/directory is the path to the directory whose ownership you want to change.
  3. Example: To change the ownership of a directory named mydir to user alice and group developers, you would run:

    sudo chown alice:developers mydir
    
  4. To change ownership recursively: If you want to change the ownership of the directory and all its contents (files and subdirectories), add the -R option:

    sudo chown -R owner:group /path/to/directory
    

    For example:

    sudo chown -R alice:developers mydir
    
  5. Verify the change: You can check the ownership of the directory using:

    ls -ld /path/to/directory
    

This will display the current owner and group of the directory.

0 Comments

no data
Be the first to share your comment!