Category filter

Script to Change Ownership of a File or Folder on Mac

Every file or folder on Mac has an owner account assigned to it. Users can assign ownership of a file or folder to a specified user using the Get Info option. Right-click on the target file or folder to access the Get Info option from the dropdown menu. When configuring multiple endpoints, changing the file ownership can be tiresome for an IT admin. With Hexnode UEM, admins can remotely change ownership of the target file or folder on multiple endpoints simultaneously by running a custom script.

Scripting Language – Bash

File extension – .sh


The Sample Scripts provided below are adapted from third-party Open-Source sites.

Change ownership of a file or folder

For example:
chown BOB Desktop/Document.txt

The chown command is used to change the owner of a specific file/folder. Keep in mind that the username field represents the user account’s short name, which is typically the name of the home directory.


  • In Bash, before inserting space while defining file or folder names, we use a backslash ‘\’ to separate the characters. This will prevent the shell interpreter from interpreting the space as a separator and assuming they were two different arguments. Hence, if the path is New Folder/myFile, we write it as New\ Folder/myFile or use single quotes as ‘New Folder/myfile’ instead.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository