Category filter
Script to change ownership of a file or folder on Mac
The user who creates a file or folder automatically becomes the owner, and by default, no other user besides the owner can modify the file upon creation. In an organizational setting, IT administrators may find it necessary to transfer the ownership of a file or folder from one user to another, particularly when an employee departs from the organization or changes roles within it. Transferring ownership to another user ensures that other team members can take over incomplete projects, helping the team meet deadlines and finish any remaining work.
Using Hexnode’s Execute Custom Script action, IT admins can remotely change the ownership of the targeted file or folder on macOS devices by executing the below script.
Scripting language – Bash
File extension – .sh
Change ownership of a file or folder
1 2 |
#!/bin/bash chown 'username' 'file path/file name with extension' |
For example:
chown Daniel /Users/Alex/Desktop/Dustin
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.
What happens at the device end?
Executing the script automatically changes the ownership of the specified file or folder to the configured user in the Sharing & Permissions setting within Get Info option on the macOS device.
No users other than the owner can modify a file/folder. The device asks for the admin credentials when other users attempt to modify the file/folder.