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 the Execute Custom Script action.

Scripting language – Bash

File extension – .sh

Disclaimer:


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.

Notes:

  • 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